Vue中
data() {
return {
/*當(dāng)前日期時(shí)間*/
nowYear: '',
nowMonth: '',
nowDate: '',
nowDay: '',
nowHours: '',
nowMinutes: '',
nowSeconds: '',
turnoverTime: ''
};
},
獲取當(dāng)前日期時(shí)間
// 獲取當(dāng)前日期時(shí)間
getNowTime() {
this.nowYear = new Date().getFullYear();
this.nowMonth = new Date().getMonth()+1;
this.nowDate = new Date().getDate();
this.nowDay = new Date().getDay();
this.nowHours = new Date().getHours();
this.nowMinutes = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
this.nowSeconds = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
this.turnoverTime = this.nowYear+'年'+this.nowMonth+'月'+this.nowDate+'日'+' '+this.nowHours+':'+this.nowMinutes+':'+this.nowSeconds;
},
獲取上周日期
let thisWeekStart; //本周周一的時(shí)間
if (this.nowDay === 0) { //周天的情況呛占;
thisWeekStart = (new Date(this.nowYear + '-' + this.nowMonth + '-' + this.nowDate)).getTime() - ((this.nowDay) + 6) * 86400000;
} else {
thisWeekStart = (new Date(this.nowYear + '-' + this.nowMonth + '-' + this.nowDate)).getTime() - ((this.nowDay) - 1) * 86400000;
}
//獲得上周時(shí)間
var prevWeekStart = thisWeekStart - 7 * 86400000;//上周周一的時(shí)間
var prevWeekEnd = thisWeekStart - 1 * 86400000;//上周周日的時(shí)間
let sTime = this.formatDate(new Date(prevWeekStart)); //開始時(shí)間
let eTime = this.formatDate(new Date(prevWeekEnd)); //結(jié)束時(shí)間
獲取上月日期
var prevCurrentYear = 0, prevCurrentMonth = 0;
if (this.nowMonth === 1) {
prevCurrentYear = this.nowYear - 1;
prevCurrentMonth = 12;
} else {
prevCurrentYear = this.nowYear;
prevCurrentMonth = this.nowMonth - 2;
}
//獲得上月時(shí)間
var prevmonthLastday = (new Date(this.nowYear, this.nowMonth-1, 1)).getTime() - 86400000;
let sTime = this.formatDate(new Date(prevCurrentYear, prevCurrentMonth, 1)); //開始時(shí)間
let eTime = this.formatDate(new Date(prevmonthLastday)); //結(jié)束時(shí)間
獲取昨天日期
let date1 = new Date();
let date2 = new Date(date1);
date2.setDate(date1.getDate() - 1);
`${date2.getFullYear()}-${date2.getMonth() + 1<10?`0${date2.getMonth() + 1}`:date2.getMonth() + 1}-${date2.getDate()}`;
獲取30天前日期
let date1 = new Date();
let date2 = new Date(date1);
date2.setDate(date1.getDate() - 30);
`${date2.getFullYear()}-${date2.getMonth() + 1<10?`0${date2.getMonth() + 1}`:date2.getMonth() + 1}-${date2.getDate()}`;