Javascript 从ngxdaterangepicker日历中的SelectedDaterRange之间获取数组中的所有日期
这是我试过的。我想获取数组中选定的enddate和startdate之间的日期。这样我就可以画出日期和通话次数之间的图表Javascript 从ngxdaterangepicker日历中的SelectedDaterRange之间获取数组中的所有日期,javascript,angular,google-cloud-firestore,Javascript,Angular,Google Cloud Firestore,这是我试过的。我想获取数组中选定的enddate和startdate之间的日期。这样我就可以画出日期和通话次数之间的图表 enumerateDaysBetweenDates(startDate, endDate) { const dates = []; const currDate = moment(startDate).startOf('day'); const lastDate = moment(endDate).startOf('day'); while(
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;
枚举日期之间的日期(开始日期、结束日期){
常数日期=[];
const currDate=时刻(startDate).startOf('day');
const lastDate=时刻(endDate).startOf('day');
while(currDate.add(1,'天').diff(lastDate)<0){
dates.push(currDate.clone().toDate());
}
console.log(日期[0]);
返回日期;
使用此
用这个
你可以这样设置函数
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;
}
其结果将是
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) {}
你可以这样设置函数
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;
}
其结果将是
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) {}
不需要片刻,使用Array.from,长度为所需天数,并使用一个构造函数将索引添加到开始日期
const msInDay=1000*3600*24;//一天中的毫秒数
const EnumerateDaysBetween Dates=(startDate,endDate)=>Array.from(
{length:(endDate.getTime()-startDate.getTime())/msInDay+1},
(索引)=>新日期(startDate.getTime()+(索引*msInDay))
);
console.log(枚举日期之间的日期(新日期('2019-01-23')、新日期('2019-01-28'));
无需片刻,使用Array.from,长度为所需天数,并使用构造函数将索引添加到开始日期
const msInDay=1000*3600*24;//一天中的毫秒数
const EnumerateDaysBetween Dates=(startDate,endDate)=>Array.from(
{length:(endDate.getTime()-startDate.getTime())/msInDay+1},
(索引)=>新日期(startDate.getTime()+(索引*msInDay))
);
console.log(EnumeratedaysBetween dates(新日期('2019-01-23')、新日期('2019-01-28'));
Hey,谢谢你,但我只希望这些日期是dd/mm/yy格式。再次感谢你Hey,谢谢你,但我只希望这些日期是dd/mm/yy格式。再次感谢你