var that = this
let date = new Date();
let currYear = date.getFullYear();
let currMonth = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth();
let currWeekDay = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
let currDate = date.getDay();
let weekStartDate = new Date(currYear, currMonth, currWeekDay - currDate + 1);
let weekEndDate = new Date(currYear, currMonth, currWeekDay + (7 - currDate));
let a = weekStartDate;
var Month = a.getMonth() + 1;
var MonthDate;
var DayDate = a.getDate();
var Day;
if (Month < 10) {
MonthDate = '0' + Month;
} else {
MonthDate = Month;
}
if (DayDate < 10) {
Day = '0' + DayDate;
} else {
Day = DayDate;
}
var mon = a.getFullYear() + "-" + MonthDate + "-" + Day;
console.log('周一',mon);
let startDate = weekStartDate.getDate() < 10 ? '0' + weekStartDate.getDate() : weekStartDate.getDate();
let endMonth = weekEndDate.getMonth() + 1;
let endDate = weekEndDate.getDate();
let endTime = new Date(new Date(date).getTime() + (3600 * 1000 * 24 * (new Date(date).getDay() == 0 ? 0 :
7 - new Date(date).getDay(date))))
var Month = endTime.getMonth() + 1;
var Day = endTime.getDate();
var Y = endTime.getFullYear() + '-';
var M = Month < 10 ? '0' + Month + '-' : Month + '-';
var D = Day + 1 < 10 ? '0' + Day : Day;
var sun = Y + M + D
console.log('周天',sun);
js获取本周一和周天日的时间
于 2022-12-29 14:50:10 首次发布