//获取两日期之间日期
function getdiffdate(stime,etime){
//初始化日期列表,数组
var diffdate = new Array();
var i=0;
//开始日期小于等于结束日期,并循环
while(stime<=etime){
diffdate[i] = stime;
//获取开始日期时间戳
var stime_ts = new Date(stime).getTime();
console.log('当前日期:'+stime +'当前时间戳:'+stime_ts);
//增加一天时间戳后的日期
var next_date = stime_ts + (24*60*60*1000);
//拼接年月日(0-11)+1
var next_dates_y = new Date(next_date).getFullYear()+'-';
var next_dates_m = (new Date(next_date).getMonth()+1 < 10)?'0'+(new Date(next_date).getMonth()+1)+'-':(new Date(next_date).getMonth()+1)+'-';
var next_dates_d = (new Date(next_date).getDate() < 10)?'0'+new Date(next_date).getDate():new Date(next_date).getDate();
stime = next_dates_y+next_dates_m+next_dates_d;
i++;
}
console.log(diffdate);
return diffdate;
}
实用函数合集
最新推荐文章于 2024-08-26 20:25:07 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)