2024.01.07 08:17
最近开发的项目用到了获取未来30天日期和星期,记录一下,简单的点滴方便以后的开发。
futureDate() {
const weeks = ['日', '一', '二', '三', '四', '五', '六']
let dateList = [], startDate = new Date(), endDate = new Date()
endDate.setDate(startDate.getDate() + 30)
while((endDate.getTime() - startDate.getTime()) > 0) {
let m = (startDate.getMonth() + 1).toString().length === 1 ? "0" + (startDate.getMonth() + 1).toString() : (startDate.getMonth() + 1)
let d = startDate.getDate().toString().length === 1 ? "0" + startDate.getDate() : startDate.getDate()
let w = weeks[startDate.getDay()]
dateList.push(m + '月' + d + '日' + " 周" + w)
startDate.setDate(startDate.getDate() + 1)
}
return dateList
}