date 当前时间
以week举例,type===next 下周,type === last为上周,其他月年,依此类推,
当前方法是获取比如说date 00:00:00到nextDay 23:59:59,或者lastDat 00:00:00到date 23:59:59,其它方法依此类推
getWeekDate (date, type) {
const day = new Date(date).getTime()
if (type === 'next') {
const nextDay = new Date(day + 6 * 24 * 60 * 60 * 1000)
return nextDay
} else {
const lastDay = new Date(day - 6 * 24 * 60 * 60 * 1000)
return lastDay
}
},
getMonthDate (date, type) {
const nowMonth = new Date(date).getMonth() + 1
const dateNow = new Date(date)
if (type === 'next') {
if (nowMonth === 12) {
return (dateNow.getFullYear() + 1) + '-01' + '-' + (dateNow.getDate() - 1)
} else {
return dateNow.getFullYear() + '-' + (dateNow.getMonth() + 2) + '-' + (dateNow.getDate() - 1)
}
} else {
if (nowMonth === 1) {
return (dateNow.getFullYear() - 1) + '-12' + '-' + (dateNow.getDate() + 1)
} else {
return dateNow.getFullYear() + '-' + dateNow.getMonth() + '-' + (dateNow.getDate() + 1)
}
}
},
getSeasonDate (date, type) {
const nowMonth = new Date(date).getMonth() + 1
const dateNow = new Date(date)
if (type === 'next') {
if (nowMonth > 10) {
return (dateNow.getFullYear() + 1) + '-' + (nowMonth + 3 - 12) + '-' + (dateNow.getDate() - 1)
} else {
return dateNow.getFullYear() + '-' + (nowMonth + 3) + '-' + (dateNow.getDate() - 1)
}
} else {
if (nowMonth < 3) {
return (dateNow.getFullYear() - 1) + '-' + (nowMonth - 3 + 12) + '-' + (dateNow.getDate() + 1)
} else {
return dateNow.getFullYear() + '-' + (nowMonth - 3) + '-' + (dateNow.getDate() + 1)
}
}
},
getYearDate (date, type) {
const nowYear = new Date(date).getFullYear()
const nowMonth = new Date(date).getMonth() + 1
const nowDate = new Date(date).getDate()
if (type === 'next') {
return new Date(new Date(nowYear + 1 + '-' + nowMonth + '-' + nowDate).getTime() - 1 * 24 * 60 * 60 * 1000).format('yyyy-MM-dd')
} else {
return new Date(new Date(nowYear - 1 + '-' + nowMonth + '-' + nowDate).getTime() + 1 * 24 * 60 * 60 * 1000).format('yyyy-MM-dd')
}
},