获得本周的开始时间
getStartDayOfWeek() {
let now = new Date(); // 当前日期
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() {
let now = new Date(); // 当前日期
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));
},
// 获取当前日期
getNowDay() {
return this.formatDate(new Date());
},
// 日期格式化
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);
},
获取本周的开始时间、结束时间、当前日期
最新推荐文章于 2024-08-02 16:50:48 发布