getOneMonthDateList () {
let daysInMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
let currentDate = new Date()
currentDate.setMonth(currentDate.getMonth() + 1)
let strYear = currentDate.getFullYear()
let strDay = currentDate.getDate()
let strMonth = currentDate.getMonth() + 1
if (((strYear % 4) === 0) & ((strYear % 100) !== 0) || ((strYear % 400) === 0)) {
daysInMonth[2] = 29
}
if (strMonth - 1 === 0) {
strYear -= 1
strMonth = 12
} else {
strMonth -= 1
}
strDay = Math.min(strDay, daysInMonth[strMonth])
if (strMonth < 10) {
strMonth = '0' + strMonth
}
if (strDay < 10) {
strDay = '0' + strDay
}
let dateStr = strYear + '-' + strMonth + '-' + strDay
const dateList = []
let startDate = new Date(dateStr)
while (true) {
startDate.setDate(startDate.getDate() + 1)
if (startDate.getTime() < currentDate.getTime()) {
if (startDate.getDate() < 10) {
// startDate.getFullYear() 获取年,此处没加上年份
dateList.push(startDate.getMonth() + '.0' + startDate.getDate())
} else {
dateList.push(startDate.getMonth() + '.' + startDate.getDate())
}
} else {
break
}
}
return dateList
}
javascript根据当前日期获取往前一个月的日期数组
最新推荐文章于 2025-03-19 14:21:27 发布