This article example describes how to obtain the current date seven days before js. Share it for your reference. The details are as follows:
//Set the date, the first seven days of the current date var myDate = new Date(); //Get today's 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);}Replenish:
getDate() returns a day of the month from the Date object (1 ~ 31).
getMonth() returns month (0 ~ 11) from Date object.
getFullYear() returns the year as four digits from the Date object.
I hope this article will be helpful to everyone's JavaScript programming.