gistfile1.txt function getPrevWeek () { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var dayWeek = date.getDay(); var dayMonth = date.getDate(); var json = { 1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30
function getPrevWeek () { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var dayWeek = date.getDay(); var dayMonth = date.getDate(); var json = { 1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31 }; if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) { // 闰年 2 月份 有 29 天 json[2] = 29; } if (dayMonth > 7) { return year + '-' + month + '-' + (dayMonth - 7); } // 上周的日期在上个月的情况 return year + '-' + (month - 1) + '-' + (json[month - 1] + dayMonth - 7) }