const now = new Date()
console.log('当前日期', now.toLocaleDateString())
getLastWeek() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var dateObj = {};
dateObj.now = year + '-' + month + '-' + day;
if(day - 7 <= 0){
var lastMonthDay = new Date(year, (parseInt(month) - 1), 0).getDate();
if(month - 1 <= 0){
dateObj.last = (year - 1) + '-' + 12 + '-' + (31 - (7 - day));
}else{
dateObj.last = year + '-' + (month - 1) + '-' + (lastMonthDay - (7 - day));
}
}else{
dateObj.last = year + '-' + month + '-' + (day -7);
}
return dateObj;
},
getLastMonth() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var dateObj = {};
dateObj.now = year + '-' + month + '-' + day;
var nowMonthDay = new Date(year, month, 0).getDate();
if(month - 1 <= 0){
dateObj.last = (year - 1) + '-' + 12 + '-' + day;
}else{
var lastMonthDay = new Date(year, (parseInt(month) - 1), 0).getDate();
if(lastMonthDay < day){
if(day < nowMonthDay){
dateObj.last = year + '-' + (month - 1) + '-' + (lastMonthDay - (nowMonthDay - day));
}else{
dateObj.last = year + '-' + (month - 1) + '-' + lastMonthDay;
}
}else{
dateObj.last = year + '-' + (month - 1) + '-' + day;
}
}
return dateObj;
},
getLast3Month() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var dateObj = {};
dateObj.now = year + '-' + month + '-' + day;
var nowMonthDay = new Date(year, month, 0).getDate();
if(month - 3 <= 0){
var last3MonthDay = new Date((year - 1), (12 - (3 - parseInt(month))), 0).getDate();
if(last3MonthDay < day){
dateObj.last = (year - 1) + '-' + (12 - (3 - month)) + '-' + last3MonthDay;
}else{
dateObj.last = (year - 1) + '-' + (12 - (3 - month)) + '-' + day;
}
}else{
var last3MonthDay = new Date(year, (parseInt(month) - 3), 0).getDate();
if(last3MonthDay < day){
if(day < nowMonthDay){
dateObj.last = year + '-' + (month - 3) + '-' + (last3MonthDay - (nowMonthDay - day));
}else{
dateObj.last = year + '-' + (month - 3) + '-' + last3MonthDay;
}
}else{
dateObj.last = year + '-' + (month - 3) + '-' + day;
}
}
return dateObj;
},
getLast6Month() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var dateObj = {};
dateObj.now = year + '-' + month + '-' + day;
var nowMonthDay = new Date(year, month, 0).getDate();
now.setMonth(now.getMonth() - 6);
dateObj.last = now.toLocaleDateString()
return dateObj;
},