function getAll(start, end) {
let dateList = [];
var startTime = getDate(start);
var endTime = getDate(end);
while ((endTime.getTime() - startTime.getTime()) >= 0) {
var year = startTime.getFullYear();
var month = startTime.getMonth() + 1 < 10 ? '0' + (startTime.getMonth() + 1) : startTime.getMonth() + 1;
var day = startTime.getDate().toString().length == 1 ? "0" + startTime.getDate() : startTime.getDate();
dateList.push(year + "-" + month + "-" + day);
startTime.setDate(startTime.getDate() + 1);
}
return dateList;
}
function getDate(datestr) {
var temp = datestr.split("-");
var date = new Date(temp[0], temp[1] - 1, temp[2]);
return date;
}
// 调用
getAll('2024-01-31','2024-02-05');
js 获取两个日期之间的每一天
最新推荐文章于 2024-08-16 10:56:25 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)