//獲取時間
getTime() {
var getNowDate = new Date();
//獲取當前日期時間
const nowYear = getNowDate.getFullYear();
let nowMonth = getNowDate.getMonth() + 1;
let nowDay = getNowDate.getDate();
if (nowMonth >= 1 && nowMonth <= 9) {
nowMonth = "0" + nowMonth;
}
if (nowDay >= 1 && nowDay <= 9) {
nowDay = "0" + nowDay;
} else if (nowDay == 1) {
nowDay = 30;
nowMonth -= 1;
}
var nowDate = nowYear + "-" + nowMonth + "-" + nowDay;
//獲取一周時間
var getOneweek = new Date(getNowDate - 7 * 24 * 3600 * 1000);
var thYear = getOneweek.getFullYear();
var thMonth = getOneweek.getMonth() + 1;
var thDay = getOneweek.getDate();
if (thMonth >= 1 && thMonth <= 9) {
thMonth = "0" + thMonth;
}
if (thDay >= 0 && thDay <= 9) {
thDay = "0" + thDay;
}
var oneweekDate = thYear + "-" + thMonth + "-" + thDay;
//獲取一個月前時間
getNowDate.setMonth(getNowDate.getMonth() - 1);
var thirtyYear = getNowDate.getFullYear();
var thirtyMonth = getNowDate.getMonth() + 1;
var thirtyDay = getNowDate.getDate();
if (thirtyMonth >= 1 && thirtyMonth <= 9) {
thirtyMonth = "0" + thirtyMonth;
}
if (thirtyDay >= 1 && thirtyDay <= 9) {
thirtyDay = "0" + thirtyDay;
}
var monthDate = thirtyYear + "-" + thirtyMonth + "-" + thirtyDay;
// 獲取三年時間
var date = new Date();
var y = date.getFullYear() - 2; // 減一是算去年時間,+ 1 是明年時間
var dateStr = y + "-" + 1 + "-" + 1;
return {
nowDate: nowDate,
oneweekDate: oneweekDate,
monthDate: monthDate,
dateStr: dateStr,
};
},