// val 1:开始时间 2:结束时间
const getDateRange(val) {
if(val == '1') {
// 获取五年前得第一天,0就是一月
const startDate = new Date(new Date().getFullYear() - 5, 0, 1)
return startDate
}else if(val == '2') {
// 获取当前年下一年的1月1日0点(本地时区)
const currentYear = new Date(new Date().getFullYear() + 1, 0, 1)
// 减去1毫秒,得到当前年的最后一刻
const endDate = new Date(currentYear.getTime() - 1)
return endDate
}
}
以上代码可用于一些需限制时间范围的时间组件内,例如Vant时间组件的min-date和max-date属性等
可根据自己需求灵活修改

被折叠的 条评论
为什么被折叠?



