getDatesBetween(startDate, endDate) {//计算之间的方法,因为数据可能会很大,所以提前计算出来
const dates = [];
const currentDate = new Date(startDate);
while (currentDate <= new Date(endDate)) {
dates.push(new Date(currentDate));
currentDate.setDate(currentDate.getDate() + 1);
}
return dates;
},
componentDay(startDate,endDate){
let that = this
let arr = []
const dateList = this.getDatesBetween(startDate, endDate);
dateList.forEach(date => {
const formattedDate = {
allDay:date.toISOString().slice(0, 10),
year:date.toISOString().slice(0, 10).split('-')[0],
month:date.toISOString().slice(0, 10).split('-')[1],
day:date.toISOString().slice(0, 10).split('-')[2],
}
arr.push(formattedDate)
});
this.timeIndex = arr.length - 1
this.timeList = arr
},
conponttmoDay(startDate){//计算下一天的时间 时间传入2023-3-3格式
const currentDate = new Date(startDate);
const tomorrow = new Date(currentDate).setDate(currentDate.getDate() + 1)
const tomorrows = new Date(tomorrow).toISOString().slice(0, 10)
console.log('tomorrows',tomorrows)
return tomorrows
},
conpontNowDay(){//计算当天的时间
const currentDate = new Date();
return currentDate.toISOString().slice(0, 10)
},
网友评论