獲取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)// 最后一個(gè)數(shù)字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
},