SOURCE

var end = new Date();
var year = end.getFullYear();
var month = end.getMonth() + 1;//0-11表示1-12月
var day = end.getDate();
var dateObj = {};
dateObj.end = year + '-' + month + '-' + day;
if (day - 7 <= 0) {   //如果在当月7日之前
    var startMonthDay = new Date(year, (parseInt(month) - 1), 0).getDate();    //1周前所在月的总天数
    if ( month - 1 <= 0 ) { //如果在当年的1月份
      dateObj.start = (year - 1) + '-' + 12 + '-' + (31 - (7 - day));
    } else {
      dateObj.start = year + '-'  +(month - 1) + '-' + (startMonthDay - (7 - day));
    }
} else if(month >= 10  ){
    dateObj.start = year + '-' + month + '-' + (day - 7);
} else {
    dateObj.start = year + '-'  + month + '-' + (day - 7);
}
console.log(JSON.stringify(dateObj))
// 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.

console.log(new Date(dateObj.start))
console.log(dateObj.start)
console.log(dateObj.end)
console.log(new Date(dateObj.start))
console.log(new Date(dateObj.end))



console 命令行工具 X clear

                    
>
console