diff --git a/src/utils/dateutils.js b/src/utils/dateutils.js index 868111a..046d1cc 100644 --- a/src/utils/dateutils.js +++ b/src/utils/dateutils.js @@ -25,6 +25,30 @@ ct_month.setTime(ct_month.getTime() - 3600 * 1000 * 24 * 30) return ct_month } +// 获取3个月之前 +export function getLastSeason() { // 默认显示上个月 + let year = new Date().getFullYear(); + let month = new Date().getMonth() - 3; + if (month < 0) { + month += 12 + year = year-1; + } + ct_month.setTime(ct_month.getTime() - 3600 * 1000 * 24 * 30) + return ct_month +} +// 获取上一年的当天 +export function getLastYear(){ + const year = new Date().getFullYear()-1; + let month = new Date().getMonth(); + // if (month === 0) { + // month = 12; + // year = year-1; + // } else if (month < 10) { + // month = '0'+month; + // } + const date = new Date().getDate() + return new Date(year,month,date,0,0,0,0) +} // 对Date的扩展,将 Date 转化为指定格式的String // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,