//获取当前一周时间的初始定义
var now = new Date();
//获取下一周时间的初始定义
var today = new Date();
var now = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7);
var weekDay = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
// 获取本周的第一天(周一)
var firstDay = new Date(now.setDate(now.getDate() - now.getDay() + (now.getDay() === 0 ? -6 : 1)));
// 存储本周的日期
var weekDates = [];
// 循环获取本周的所有日期
for (var i = 0; i < 7; i++) {
var tempDate = new Date(firstDay);
tempDate.setDate(firstDay.getDate() + i);
var year = tempDate.getFullYear();
var month = tempDate.getMonth() + 1;
var day = tempDate.getDate();
weekDates.push({
week: weekDay[i],
date: year + '-' + (month < 10 ? '0' : '') + month + '-' + (day < 10 ? '0' : '') + day
});
}
console.log(weekDates)
12-22
1264
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-18
2043
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-31
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交