代码如下
// 返回近 dayNum 天日期数组
getRecentDay(dayNum) {
let currentDate = new Date();
let dayNumDaysAgo = new Date(
currentDate.getTime() - dayNum * 24 * 60 * 60 * 1000
);
let recentDays = [];
for (let i = 0; i < dayNum; i++) {
let date = new Date(dayNumDaysAgo.getTime() + i * 24 * 60 * 60 * 1000);
let month = (date.getMonth() + 1).toString().padStart(2, "0");
let day = date.getDate().toString().padStart(2, "0");
recentDays.push(`${month}.${day}`);
}
return recentDays;
},
效果如下