关于日期的方法们
getDate:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate
setDate:
JavaScript Date setDate() 方法
const now = new Date();
const sevenDaysAgo = new Date();
sevenDaysAgo.setDate(now.getDate() - 7);
这段代码:
getSevenDay() {
const now = new Date();
const sevenDaysAgo = new Date();
sevenDaysAgo.setDate(now.getDate() - 7);
// this.queryParams.pickTime = [sevenDaysAgo, now];
this.pickTimeArr = [sevenDaysAgo, now];
const yearEnd = now.getFullYear();
const monthEnd = String(now.getMonth() + 1).padStart(2, '0');
const dayEnd = String(now.getDate()).padStart(2, '0');
// 获取当前时间
const hoursNow = String(now.getHours()).padStart(2, '0');
const minutesNow = String(now.getMinutes()).padStart(2, '0');
const secondsNow = String(now.getSeconds()).padStart(2, '0');
this.queryParams.pickTimeEnd = `${yearEnd}-${monthEnd}-${dayEnd} ${hoursNow}:${minutesNow}:${secondsNow}`;
const yearStart = sevenDaysAgo.getFullYear();
const monthStart = String(sevenDaysAgo.getMonth() + 1).padStart(2, '0');
const dayStart = String(sevenDaysAgo.getDate()).padStart(2, '0');
this.queryParams.pickTimeStart = `${yearStart}-${monthStart}-${dayStart} ${hoursNow}:${minutesNow}:${secondsNow}`;
}