/** * 获取当月的日期集合(yyyy-MM-dd) */ function currentMonthDays() { // 获取标准时间 const date = new Date(); // 获取当天日期 const currentDay = date.getDate(); // 获取当前月份(实际月份需要加1) const currentMonth = date.getMonth() + 1 < 10 ? '0' + date.getMonth() + 1 : date.getMonth() + 1; // 获取当前年份 const currentYear = date.getFullYear(); // 获取当前月有多少天 const currentMonthDays = new Date(currentYear, currentMonth, 0).getDate(); // 当前月份所有日期集合 const currentMonthArr = []; for (let day = 1; day <= currentMonthDays; day++) { // 截至当前日期为止 if (day <= currentDay) { // 年月日(yyyy-MM-dd) let dateItem = currentYear + "-" + currentMonth + "-" + (day < 10 ? '0' + day : day) currentMonthArr.push(dateItem) } } return currentMonthArr; }