//获取时间
getDay(day){ //这里的day是时间(列如:7,-7)
let today = new Date();
let targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
today.setTime(targetday_milliseconds); //注意,这行是关键代码,到这时间已经转行为毫秒
return this.format(today)
},
//格式化日期
format(date){
let year = date.getFullYear()
let month = date.getMonth() + 1
let day = date.getDate()
if (month >= 1 && month <= 9) { month = `0${month}` }
if (day >= 1 && day <= 9) { day = `0${day}` }
return `${year}-${month}-${day}`
},
js获取近7天、近一个月、近三个月的时间
最新推荐文章于 2024-07-23 17:12:42 发布