const today = new Date(); // 获取当前日期
const dateArray = [];
const dayArray = [];
// 计算前10天
for (let i = 10; i > 0; i--) {
const pastDate = new Date(today);
pastDate.setDate(today.getDate() - i);
dateArray.push(pastDate.toISOString().split('T')[0]); // 格式化日期
dayArray.push(pastDate.getDate()); // 提取日
}
// 计算后30天
for (let i = 0; i < 30; i++) {
const futureDate = new Date(today);
futureDate.setDate(today.getDate() + i);
dateArray.push(futureDate.toISOString().split('T')[0]); // 格式化日期
dayArray.push(futureDate.getDate()); // 提取日
}
dates.value = dateArray; // 更新日期数组
days.value = dayArray; // 更新日数组
标签:pastDate,10,futureDate,const,天和后,日期,today,getDate
From: https://blog.csdn.net/Llongfyjc/article/details/143251071