获取当前周对应的日期
//表示当前已经的日期
var currentFirstDate;
/* 设置日期*/
var setDate = function(date) {
var week = date.getDay() - 1;
date = addDate(date, week * -1);
console.log(date)
currentFirstDate = new Date(date);
var arr = [];
//循环入数组
for(var i = 0; i < 7; i++) {
arr.push(formatDate(i == 0 ? date : addDate(date, 1)))
}
return arr
};
function getMonDate() { var d = new Date(), day = d.getDay(), date = d.getDate(); if(day == 1) return d; if(day == 0) d.setDate(date - 6); else d.setDate(date - day + 1); return d; } // 0-6转换成中文名称 function getDayName(day) { var day = parseInt(day); if(isNaN(day) || day < 0 || day > 6) return false; var weekday = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; return weekday[day]; } //获取当前周的所有日期 function getWeekDate(){ // d是当前星期一的日期对象 var d = getMonDate(); var arr = []; for(var i = 0; i < 7; i++) { // arr.push(d.getFullYear() + '年' + (d.getMonth() + 1) + '月' + d.getDate() + '日(' + getDayName(d.getDay()) + ')'); arr.push((d.getMonth() + 1) + '-' + d.getDate() + '(' + getDayName(d.getDay()) + ')'); d.setDate(d.getDate() + 1); } console.log(arr);
return arr; }
//控制台输出当前周对应的日期 console.log(getWeekDate())