//获取以当天开头的一周的时间
getWeekDate() {
var date = new Date(‘2020-12-30’);
var year = date.getFullYear();
var month = date.getMonth();
var week = date.getDay();
var month = month + 1;
var day = date.getDate();
//获取本月最后一天
var LastDayOfLastMonth = new Date(year, month, 0).getDate()
// week:周几,day:几号
var weekArr = [{ week, day, month, year }, { week: ‘’, day: ‘’, month, year }, { week: ‘’, day: ‘’, month, year }, { week: ‘’, day: ‘’, month, year }, { week: ‘’, day: ‘’, month, year }, { week: ‘’, day: ‘’, month, year }, { week: ‘’, day: ‘’, month, year }];
// 本周内今天的后几天
for (var i = 1; i <7; i++) {
// 判断是否为下一月
if (day + i > LastDayOfLastMonth) {
console.log(‘weekArr’,weekArr[i])
if (month == 12) {
weekArr[i].day = ‘0’ + 1
weekArr[i].year = year + 1
weekArr[i].month = ‘0’ + 1
month = 1
day = 1
year = year+1
} else {
day = 1
month = month+1
console.log(month)
weekArr[i].day = ‘0’ + 1
if (month < 10) {
weekArr[i].month = ‘0’ + (month)
} else {
weekArr[i].month = month
}
}
} else {
day = day+1
if (day < 10) {
weekArr[i].day = ‘0’ + day;
} else {
weekArr[i].day = day
}
if (month < 10) {
weekArr[i].month = ‘0’ + month
} else {
weekArr[i].month = month
}
}
if (weekArr[i - 1].week < 7) {
weekArr[i].week = weekArr[i - 1].week + 1
} else {
weekArr[i].week = 1
}
}
for (var i = 0; i < weekArr.length; i++) {
if(weekArr[i].week==1){
weekArr[i].week='周一'
}else if(weekArr[i].week==2){
weekArr[i].week='周二'
}else if(weekArr[i].week==3){
weekArr[i].week='周三'
}else if(weekArr[i].week==4){
weekArr[i].week='周四'
}else if(weekArr[i].week==5){
weekArr[i].week='周五'
}else if(weekArr[i].week==6){
weekArr[i].week='周六'
}else if(weekArr[i].week==7){
weekArr[i].week='周天'
}
}
if(weekArr[0].month<10){
weekArr[0].month='0'+weekArr[0].month
}
if(weekArr[0].day<10){
weekArr[0].day='0'+weekArr[0].day
}
}