computed: {
handleDate() {
return function(value) {
let today = new Date() // 获取当前日期和时间
let threeDaysBefore = new Date(today.getTime() - value * 24 * 60 * 60 * 1000)
let year = threeDaysBefore.getFullYear() // 获取年份
let month = threeDaysBefore.getMonth() + 1 // 获取月份(注意,月份是从0开始的,所以要加1)
let date = threeDaysBefore.getDate() // 获取日期
month = month < 10 ? '0' + month : month
date = date < 10 ? '0' + date : date
return `${year}${month}${date}`
}
}
},
近一天:this.handleDate(0)-this.handleDate(0);
近三天:this.handleDate(2)-this.handleDate(0);
近七天:this.handleDate(6)-this.handleDate(0);
获取当前日期到前n天的日期范围
最新推荐文章于 2024-05-21 23:21:19 发布