js 獲取當前日期到之後一個月30天的日期區間
阿新 • • 發佈:2019-02-21
tel ons lis let string div console var set
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)
js 獲取當前日期到之後一個月30天的日期區間