js获取当前日期的前后日期
var timeArray=null;
var currentTime= (new Date).getTime();
for (var i=-13;i<=0;i++){
timeArray.push(getNextDate(currentTime,i))
}
function getNextDate(date,day) {//data基准时间的时间戳,day:第几天
var dd = new Date(date);
dd.setDate(dd.getDate() + day);
var y = dd.getFullYear();
var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() +1;
var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
return y + "-" + m + "-" + d;
}
得到日期数组,例['2020-02-16','2020-02-17','2020-02-18','2020-02-19','2020-02-20']