1.计算本周的开始日期
function getCurWeek() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1; //获取当前月份(0-11,0代表1月)
var date = now.getDate(); //获取当前日(1-31)
var day = now.getDay(); //获取当前星期X(0-6,0代表星期天)
n = day !== 0 ? day - 1 : 7 - 1;
if (date - day >= 0) { //本周开始日期在当前月份
date = date - n;
} else { //在上一个月份
if (month != 1) { //在当前年
month -= 1;
var last = new Date(year, month, 0);
var lastDate = last.getDate();
date = lastDate + date - n;
} else { //在上一年12月份
year -= 1;
month = 12;
date = 31 + date - n;
}
}
return year + '-' + month + '-' + date;
}