87,970
社区成员
发帖
与我相关
我的任务
分享
// 获取指定日期所在周的七天的日期
function getWeekDay(s) {
var dateStringReg = /^\d{4}[/-]\d{1,2}[/-]\d{1,2}$/;
if (s.match(dateStringReg)) {
var year = parseInt(s.substr(0, 4), 10);
var month = parseInt(s.substr(5, 2), 10);
var date = parseInt(s.substr(8, 2), 10);
var dt = new Date(year, month - 1, date);
var day = dt.getDay();
var today = day !== 0 ? day : 7;
var re = [];
for (var i = 1; i < 8; i++) {
var t = new Date(year, month - 1, date + i - today);
re.push(t.getFullYear() + '-' + (t.getMonth() + 1) + '-' + t.getDate());
}
return re;
} else {
throw new Error('dateString should be like "yyyy-mm-dd" or "yyyy/mm/dd"');
}
}
// 获取指定日期所在周的七天的日期
function getWeekDay(str) {
var dateStringReg = /^\d{4}[/-]\d{1,2}[/-]\d{1,2}$/;
if (str.match(dateStringReg)) {
var year = parseInt(s.substr(0, 4), 10);
var month = parseInt(s.substr(5, 2), 10);
var date = parseInt(s.substr(8, 2), 10);
var dt = new Date(year, month - 1, date);
var day = dt.getDay();
var today = day !== 0 ? day : 7;
var re = [];
for (var i = 1; i < 8; i++) {
var t = new Date(year, month - 1, date + i - today);
re.push(t.getFullYear() + '-' + (t.getMonth() + 1) + '-' + t.getDate());
}
return re;
} else {
throw new Error('dateString should be like "yyyy-mm-dd" or "yyyy/mm/dd"');
}
}