效果图
代码如下:
getWeekStartEnd = (date) => {
let oneDayTime = 24 * 60 * 60 * 1000;
let now = new Date(date);
let nowTime = now.getTime()
let day = now.getDay();
if (day == 0) {
let end = moment(new Date(date)).format("YYYY-MM-DD")
let start = moment(new Date(date) - 6 * oneDayTime).format("YYYY-MM-DD")
return {start, end}
} else {
let oneDayTime = 24 * 60 * 60 * 1000;
let MondayTime = nowTime - (day - 1) * oneDayTime;
let SundayTime = nowTime + (7 - day) * oneDayTime;
let start = moment(new Date(MondayTime)).format("YYYY-MM-DD");
let end = moment(new Date(SundayTime)).format("YYYY-MM-DD");
return {start,end}
}
}