selectDate(start, end) {
const startTime = this.getDate(start);
const endTime = this.getDate(end);
while ((endTime.getTime() - startTime.getTime()) >= 0) {
const year = startTime.getFullYear();
const month = (startTime.getMonth() + 1).toString().length === 1 ? '0' + (startTime.getMonth() + 1).toString() : (
startTime.getMonth() + 1);
const day = startTime.getDate().toString().length === 1 ? '0' + startTime.getDate() : startTime.getDate();
const weekObj = new Date(`${year}-${month}-${day}`);
const weekday = new Array(7);
weekday[0] = '日';
weekday[1] = '一';
weekday[2] = '二';
weekday[3] = '三';
weekday[4] = '四';
weekday[5] = '五';
weekday[6] = '六';
const i = weekObj.getDay();
this.dateList.push({
data: `${year}-${month}-${day}`,
wek: `${weekday[i]}`
});
startTime.setDate(startTime.getDate() + 1);
}
// console.log(this.dateList); 日期
}
js 中根据起止时间 获取中间的所有日期 及星期几
最新推荐文章于 2023-03-07 16:29:20 发布