1、获取月份的第一天和最后一天
//获取指定日期所在月份的第一天和最后一天
function getfirstDateAndlastDate(dateStr){
let date = new Date(dateStr);
let year = date.getFullYear();
let month = date.getMonth() + 1;
if(month > 12){
month = 1;
year++;
}
if (month < 10) {
month = '0' + month
}
let monthLastDay = new Date(year, month, 0).getDate();
let firstDate = year + '-' + month + '-' + '01';
let lastDate = year + '-' + month + '-' + monthLastDay;
let result={
firstDate,
lastDate
}
return result
}
2、指定日期范围遍历
在这里插入代码片