获取两个日期间的所有日期
Posted freddyhuang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取两个日期间的所有日期相关的知识,希望对你有一定的参考价值。
/** ***获取两个日期间的所有日期 ***默认start<end **/ getBetweenDateStr(‘2017-07-08‘,‘2017-07-22‘); function getBetweenDateStr(start,end){ var result = []; var beginDay = start.split("-"); var endDay = end.split("-"); var diffDay = new Date(); var dateList = new Array; var i = 0; diffDay.setDate(beginDay[2]); diffDay.setMonth(beginDay[1]-1); diffDay.setFullYear(beginDay[0]); result.push(start); while(i == 0){ var countDay = diffDay.getTime() + 24 * 60 * 60 * 1000; diffDay.setTime(countDay); dateList[2] = diffDay.getDate(); dateList[1] = diffDay.getMonth() + 1; dateList[0] = diffDay.getFullYear(); if(String(dateList[1]).length == 1){dateList[1] = "0"+dateList[1]}; if(String(dateList[2]).length == 1){dateList[2] = "0"+dateList[2]}; result.push(dateList[0]+"-"+dateList[1]+"-"+dateList[2]); if(dateList[0] == endDay[0] && dateList[1] == endDay[1] && dateList[2] == endDay[2]){ i = 1; } }; console.log(result); return result; };
以上是关于获取两个日期间的所有日期的主要内容,如果未能解决你的问题,请参考以下文章