gpt4 book ai didi

javascript - 从 ngxdaterangepicker 日历中以 Angular 获取选定日期范围之间的数组中的所有日期

转载 作者:行者123 更新时间:2023-11-28 03:22:29 25 4
gpt4 key购买 nike

这是我尝试过的。我想获取数组中选定的结束日期和开始日期之间的日期。这样我就可以绘制日期和调用次数之间的图表。

enumerateDaysBetweenDates(startDate, endDate) {
const dates = [];
const currDate = moment(startDate).startOf('day');
const lastDate = moment(endDate).startOf('day');

while(currDate.add(1, 'days').diff(lastDate) < 0) {
dates.push(currDate.clone().toDate());
}
console.log(dates[0]);
return dates;

最佳答案

你可以这样设置功能

function enumerateDaysBetweenDates(startDate, endDate) {
let dates = [];
while(startDate.getTime() <= endDate.getTime()) {
let initDate = new Date(startDate);
dates.push(initDate.getDay() + '/' + (initDate.getMonth() + 1) + '/' + initDate.getYear());
startDate.setTime(startDate.getTime() + 24*60*60*1000); // adding one day
}
return dates;
}

像这样使用它

enumerateDaysBetweenDates(new Date('2019-11-12'),new Date('2019-11-20'));

其结果将是

0: Tue Nov 12 2019 03:00:00 GMT+0300 (GMT+03:00) {}
1: Wed Nov 13 2019 03:00:00 GMT+0300 (GMT+03:00) {}
2: Thu Nov 14 2019 03:00:00 GMT+0300 (GMT+03:00) {}
3: Fri Nov 15 2019 03:00:00 GMT+0300 (GMT+03:00) {}
4: Sat Nov 16 2019 03:00:00 GMT+0300 (GMT+03:00) {}
5: Sun Nov 17 2019 03:00:00 GMT+0300 (GMT+03:00) {}
6: Mon Nov 18 2019 03:00:00 GMT+0300 (GMT+03:00) {}
7: Tue Nov 19 2019 03:00:00 GMT+0300 (GMT+03:00) {}
8: Wed Nov 20 2019 03:00:00 GMT+0300 (GMT+03:00) {}

关于javascript - 从 ngxdaterangepicker 日历中以 Angular 获取选定日期范围之间的数组中的所有日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59006688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com