//获得本周的开始时间:
getStartDayOfWeek(time) {
let now = new Date(time); // 当前日期
let nowDayOfWeek = now.getDay(); // 今天本周的第几天
let day = nowDayOfWeek || 7;
let nowDay = now.getDate(); // 当前日
let nowMonth = now.getMonth(); // 当前月
return this.formatDate(new Date(now.getFullYear(), nowMonth, nowDay + 1 - day));
},
//获得本周的结束时间:
getEndDayOfWeek(time) {
let now = new Date(time); // 当前日期
let nowDayOfWeek = now.getDay(); // 今天本周的第几天
let day = nowDayOfWeek || 7;
let nowDay = now.getDate(); // 当前日
let nowMonth = now.getMonth(); // 当前月
return this.formatDate(new Date(now.getFullYear(), nowMonth, nowDay + 7 - day));
},
// 日期格式化
formatDate(date) {
let myyear = date.getFullYear();
let mymonth = date.getMonth() + 1;
let myweekday = date.getDate();
if (mymonth < 10) {
mymonth = '0' + mymonth;
}
if (myweekday < 10) {
myweekday = '0' + myweekday;
}
return (myyear + '-' + mymonth + '-' + myweekday);
}
vue项目中使用日期获取今日,昨日,上周,下周,上个月,下个月的数据:
https://www.cnblogs.com/Old-vegetable-chicken/p/14206593.html