// 获取三个月后的所有日期
function getDatesOfLastThreeMonths() {
const today = new Date();
const dates = [];
for (let i = 0; i <= 2; i++) {
const year = today.getFullYear();
const month = today.getMonth() + i; // 获取当前月份之前的月份
const daysInMonth = new Date(year, month + 1, 0).getDate(); // 获取月份的天数
// 获取月份的第一天和最后一天
const firstDay = today;
const lastDay = new Date(this.getLastThreeMonthsToday().toISOString());
// 获取每个月的所有日期
for (let j = firstDay; j <= lastDay;) {
dates.push(new Date(j));
j.setDate(j.getDate() + 1);
}
}
return dates;
},
function getLastThreeMonthsToday() {
const today = new Date();
today.setMonth(today.getMonth() + 2);
return today;
},
const dates = this.getDatesOfLastThreeMonths();
console.log(dates)
js 获取当前时间后三个月的所有日期list
最新推荐文章于 2024-07-19 12:58:53 发布