判断给定两个日期之间的间隔天数,是否超过某短时间
isOutPass (firstDate, secondDate, limit) {
if (!firstDate || !secondDate || !limit) {
return false
}
const firstDateTimestamp = new Date(firstDate.replace(/-/g, '/')).getTime()
const secondDateTimestamp = new Date(secondDate.replace(/-/g, '/')).getTime()
const limitTimestamp = limit * 24 * 60 * 60 * 1000
if (Math.abs(firstDateTimestamp - secondDateTimestamp) > limitTimestamp) {
return false
}
return true
}
获取当前日期和30天前的日期
getDefaultData () {
const date1 = new Date()
const date2 = new Date(date1)
date2.setDate(date1.getDate() - 30)
const agoDay = `${date2.getFullYear()}-${date2.getMonth() + 1 < 10 ? `0${date2.getMonth() + 1}` : date2.getMonth() + 1}-${date2.getDate()}`
// 当前日期
const nowDay = `${date1.getFullYear()}-${date1.getMonth() + 1 < 10 ? `0${date1.getMonth() + 1}` : date1.getMonth() + 1}-${date1.getDate()}`
return [agoDay, nowDay]
},