1.获取当前日期上周的周一和周日日期
代码如下(示例):
this.time = new Date() //当前日期,也可写为“2022-09-09”
this.starttime = this.getTime(this.time);
this.endtime = this.getTime2(this.time);
this.time = this.starttime;
console.log(this.starttime,this.endtime)
getTime2(datTime2) {
const datTime = new Date(datTime2).getTime(); //获取当前日期毫秒数
const time = 7 * 24 * 60 * 60 * 1000; // 定义一周的毫秒数
const num = new Date(datTime - time).getDay() === 0 ? 7 : new Date(datTime - time).getDay();
const numRI = new Date(datTime - time + (7 - num) * 24 * 60 * 60 * 1000)
.toLocaleDateString()
.replace(/\//g, "-"); //获取上周日时间
return numRI;
},
getTime(datTime1) {
const datTime = new Date(datTime1).getTime(); //获取当前日期毫秒数
const time = 7 * 24 * 60 * 60 * 1000; // 定义一周的毫秒数
const num = new Date(datTime - time).getDay() === 0 ? 7 : new Date(datTime - time).getDay();
const numYI = new Date(datTime - time - (num - 1) * 24 * 60 * 60 * 1000)
.toLocaleDateString()
.replace(/\//g, "-"); //获取上周一时间(
return numYI;
},