// 获取三个月后的所有日期 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)
标签:const,list,js,获取,日期,三个 From: https://www.cnblogs.com/ayuaichiyu/p/18068812