js 获取当前日后_未来_30天每一天日期

js 获取当前日后_未来_30天每一天日期

// js 获取当前日期到之后一个月30天的日期区间
var dateList = [];
let startDate = new Date();
let endDate = new Date();
endDate.setDate(startDate.getDate() + 30);
while ((endDate.getTime() - startDate.getTime()) >= 0) {
    let month = (startDate.getMonth() + 1).toString().length === 1 ? "0" + (startDate.getMonth() + 1).toString() : (
        startDate.getMonth() + 1);
    let day = startDate.getDate().toString().length === 1 ? "0" + startDate.getDate() : startDate.getDate();
    dateList.push(month + "-" + day);
    startDate.setDate(startDate.getDate() + 1);
}
console.log(dateList)
// ["11-06", "11-07", "11-08", "11-09", "11-10", "11-11", "11-12", "11-13", "11-14", "11-15", "11-16", "11-17", "11-18", "11-19", "11-20", "11-21", "11-22", "11-23", "11-24", "11-25", "11-26", "11-27", "11-28", "11-29", "11-30", "12-01", "12-02", "12-03", "12-04", "12-05", "12-06"]

 

posted @ 2019-12-10 15:03  wxid_m2pywu7fxu1f  阅读(1546)  评论(0编辑  收藏  举报