获取30天前的日期,同理也可获取n天前的日期
getMothDate() {
let dateObj = {}
let endDate =new Date()
let year = endDate.getFullYear()
let month = endDate.getMonth() +1
let day = endDate.getDate()
dateObj.end =`${year}-${month <10 ?'0' + month : month}-${day <10 ?'0' + day : day}`
// 获取三十天前日期
let startDate =new Date(endDate -1000 *60 *60 *24 *30)// 最后一个数字30可改,30天的意思
let lastY = startDate.getFullYear()
let lastM = startDate.getMonth() +1
let lastD = startDate.getDate()
dateObj.start =`${lastY}-${lastM <10 ?'0' + lastM : lastM}-${lastD <10 ?'0' + lastD : lastD}`
return dateObj
},