js实现获取两个日期之间所有日期区间
Date.prototype.format = function() {
var s = '';
var mouth = (this.getMonth() + 1)>=10?(this.getMonth() + 1):('0'+(this.getMonth() + 1));
var day = this.getDate()>=10?this.getDate():('0'+this.getDate());
s += this.getFullYear() + '-';
s += mouth + "-";
s += day;
return (s);
};
function getAll(begin, end) {
var ab = begin.split("-");
var ae = end.split("-");
var db = new Date();
db.setUTCFullYear(ab[0], ab[1] - 1, ab[2]);
var de = new Date();
de.setUTCFullYear(ae[0], ae[1] - 1, ae[2]);
var unixDb = db.getTime();
var unixDe = de.getTime();
for (var k = unixDb; k <= unixDe;) {
alert((new Date(parseInt(k))).format());
k = k + 24 * 60 * 60 * 1000;
}
}
getAll('2017-02-27', '2017-03-02');