時間默認七天並且判斷時間段不能超出七天

getYear(date) {
      return date.getFullYear().toString();
 },
getMonth(date) {
        return this.formatDateNumber(date.getMonth() + 1);
},
getDay(date) {
       return this.formatDateNumber(date.getDate());
},
formatDateNumber(num) {
       return num >= 10 ? num.toString() : '0' + num;
},
formatDate(date) {
        const newDate = new Date(date);
        return this.getYear(newDate) + '-' + this.getMonth(newDate) + '-' + this.getDay(newDate);
},
// 默認查詢七天
var defaultTime= [(new Date().getTime() - 3600 * 1000 * 24 * 6), new Date()]
formatDate(this.defaultTime[0]) + ' 00:00:00',
formatDate(this.defaultTime[1]) + ' 23:59:59'
// 判斷不能超出七天
const startTimestamp = new Date(params.startTime).getTime();
const endTimestamp = new Date(params.endTime).getTime();
if ((endTimestamp - startTimestamp) > 7 * 24 * 60 * 60 * 1000) {
   this.$message.warning('查詢範圍不能超過一週');
   return;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章