获取今天包括未来几天数据(带周几)
getNextFiveDays() {
const today = new Date();
const days = [];
for (let i = 0; i < 14; i++) {
const day = new Date(today);
day.setDate(today.getDate() + i);
days.push(day);
i == 0 ? days.push('今天') : '';
i == 1 ? days.push('明天') : '';
i == 2 ? days.push('后天') : '';
i >= 3? days.push(this.reweekdays(day.getDay())) : '';
}
console.log('days',days)
var arr=[]
days.map((item,idx)=>{
if(idx%2==0){
let date = new Date(item)
console.log('item',item)
let Y = date.getFullYear() + '-'
let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
var dates=Y + M + D
console.log('=========',dates)
arr.push({
data:dates,
a:days[idx+1]
})
}
})
console.log('arr',arr)
// return days.map((date, index) => index % 2 == 0 ? `${date.getMonth() + 1}.${date.getDate()}` : date);
},
reweekdays(type) {
const weekdays = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
return weekdays[type]
},
this.getNextFiveDays()