获取当月天数
getTotalDay(year, month) {
const list = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if ((!(year % 4) && (year % 100) || !(year % 400))) {
// 闰年
list[1] = 29;
}
return list[month];
}
const time = new Date();
const days = new Date(time.getFullYear(), time.getMonth(),0);
获取工作日
getNoWeekendDateList(length, haveToday = true) {
const time = new Date(2021, 2, 28);
const currentYear = time.getFullYear();
const currentMonth = time.getMonth() + 1;
const currentDate = time.getDate();
const currentTotalDay = this.getTotalDay(currentYear, currentMonth);
const dayList = () => {
let tempList;
if (haveToday) {
tempList = [...Array(currentTotalDay - currentDate + 1)].map((e, i) => i + currentDate);
} else {
tempList = [...Array(currentTotalDay - currentDate)].map((e, i) => i + currentDate + 1);
}
const gap = length + 2 - tempList.length
if (gap > 0) {
tempList.push(...[...Array(gap)].map((e, i) => i + 1).filter(i => ![0, 6].includes(new Date(currentYear, currentMonth, i).getDay()),
));
console.log('gap', gap);
}
console.log('tempList', tempList);
return tempList;
};
return dayList().filter(i => ![0, 6].includes(new Date(currentYear, currentMonth - 1, i).getDay())).slice(0, 6);
},
getTotalDay(year, month) {
const list = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if ((!(year % 4) && (year % 100) || !(year % 400))) {
// 闰年
list[2] = 29;
}
return list[month];
},
获取下一天
tempToday = new Date();
tempDate = new Date(tempToday.setDate(tempToday.getDate() + i));