列出指定时间范围内的月份
/**
* 列出指定时间范围内的月份
* @param startDate 开始时间
* @param endDate 结束时间
* @return {*[]}
*/
export function listMonthsBetweenDates(startDate, endDate) {
let months = [];
let current = startDate;
while (current <= endDate) {
months.push(new Date(current));
current.setMonth(current.getMonth() + 1);
}
return months;
}
列出指定时间范围内的日期
/**
* 列出指定时间范围内的日期
* @param startDate 开始时间
* @param endDate 结束时间
* @return {*[]}
*/
export function listDatesWithDayOfWeek(startDate, endDate) {
let dates = [];
let currentDate = new Date(startDate);
while (currentDate <= endDate) {
let dayOfWeek = currentDate.getDay(); // 0-6, 0是周日
let dayOfWeekName = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][dayOfWeek];
dates.push({
date: new Date(currentDate),
dayOfWeek: dayOfWeekName
});
currentDate.setDate(currentDate.getDate() + 1);
}
return dates;
}
获取哪年的哪个月有多少天
/**
* 获取哪年的哪个月有多少天
* @param year 年
* @param month 月
* @return {number}
*/
export function getDaysInMonth(year, month) {
return new Date(year, Number(month), 0).getDate();
}