jquery获取两个日期之间的所有日期

xiaoxiao2021-02-28  54

jquery获取两个日期之间的所有日期

$(function() { Date.prototype.format = function() { var s = ''; s += this.getFullYear() + '-'; // 获取年份。 if((this.getMonth() + 1) >= 10) {// 获取月份。 s += (this.getMonth() + 1) + "-"; } else { s += "0" + (this.getMonth() + 1) + "-"; } if(this.getDate() >= 10) {// 获取日。 s += this.getDate(); } else { s += "0" + this.getDate(); } 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(); var str = ""; for(var k = unixDb + 24 * 60 * 60 * 1000; k < unixDe;) { str += (new Date(parseInt(k))).format() + ","; k = k + 24 * 60 * 60 * 1000; } console.log(str); return str; } getAll('2017-06-24', '2017-07-02'); })

效果:

转载请注明原文地址: https://www.6miu.com/read-2621841.html

最新回复(0)