<script>
//获取时间段 (一周的时间 七天)
var formatDate = function(date) {
var year = date.getFullYear(); //年
var month = date.getMonth() + 1; //月
var day = date.getDate(); //日;
return year + "-" + month + "-" + day;
};
var addDate = function(date, n) {
date.setDate(date.getDate() + n);
return date;
};
var setDate = function(date) {
var week = date.getDay() - 1;
date = addDate(date, week * -1);
var weekList = [];
for (var i = 0; i < 7; i++) {
weekList[i] = formatDate(i == 0 ? date : addDate(date, 1));
}
return weekList;
};
var lastWeek = setDate(addDate(new Date(),-7)); //上周
var thisWeek = setDate(addDate(new Date(), 0)); //本周
var nextWeek = setDate(addDate(new Date(), +7)); //下周
var today = formatDate(new Date()); //今日日期
</script>