一显示当天:
效果图:
getMonthAgo1 () {
let currDate = new Date()
let y = currDate.getFullYear()
let m = currDate.getMonth()
let d = currDate.getDate()
let str = moment(new Date(y, m, d)).format('yyyyMMDD')
return str
},
二:显示前后一年
效果图:
getOneMonthAgo () {
let currDate = new Date()
let y = currDate.getFullYear()
let m = currDate.getMonth()
let d = currDate.getDate()
if (m - 1 < 0) {
y -= 1
m = 11 - (0 - m)
} else {
m = m - 1
}
if (new Date(y, m + 1, 0).getDate() < d) {
d = new Date(y, m + 1, 0).getDate()
}
let str = moment(new Date(y, m, d)).format('yyyyMMDD')
return str
},