JavaScript method to get a date in a range
- 2020-06-01 08:11:57
- OfStack
This example shows how JavaScript gets a range of dates. Share with you for your reference. The specific analysis is as follows:
Specifies the start and end times, and all the dates in the range are put into an array
Date.prototype.addDays = function(days) {
var dat = new Date(this.valueOf());
dat.setDate(dat.getDate() + days);
return dat;
};
function getDates(startDate, stopDate) {
var dateArray = [];
var currentDate = startDate;
while (currentDate <= stopDate) {
dateArray.push(self.formatDate(currentDate));
currentDate = currentDate.addDays(1);
}
return dateArray;
}
I hope this article has been helpful to your javascript programming.