Home > Web Front-end > JS Tutorial > js method to get seven days before the current date_javascript skills

js method to get seven days before the current date_javascript skills

WBOY
Release: 2016-05-16 16:12:07
Original
1756 people have browsed it

The example in this article describes the js method of obtaining the seven days before the current date. Share it with everyone for your reference. The details are as follows:

//设置日期,当前日期的前七天
var myDate = new Date(); //获取今天日期
myDate.setDate(myDate.getDate() - 7);
var dateArray = []; 
var dateTemp; 
var flag = 1; 
for (var i = 0; i < 7; i++) {
    dateTemp = (myDate.getMonth()+1)+"-"+myDate.getDate();
    dateArray.push(dateTemp);
    myDate.setDate(myDate.getDate() + flag);
}
Copy after login

Supplement:

getDate() returns the day of the month (1 ~ 31) from the Date object.
getMonth() returns the month (0 ~ 11) from a Date object.
getFullYear() Returns the year as a four-digit number from a Date object.

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template