SOURCE

let date = new Date()
// 通过时间戳计算
let defalutStartTime = date.getTime() - 7 * 24 * 3600 * 1000 // 转化为时间戳
let defalutEndTime = date.getTime()
let startDateNs = new Date(defalutStartTime)
let endDateNs = new Date(defalutEndTime)
// 月,日 不够10补0
defalutStartTime = startDateNs.getFullYear() + '-' + ((startDateNs.getMonth() + 1) >= 10 ? (startDateNs.getMonth() + 1) : '0' + (startDateNs.getMonth() + 1)) + '-' + (startDateNs.getDate() >= 10 ? startDateNs.getDate() : '0' + startDateNs.getDate())
defalutEndTime = endDateNs.getFullYear() + '-' + ((endDateNs.getMonth() + 1) >= 10 ? (endDateNs.getMonth() + 1) : '0' + (endDateNs.getMonth() + 1)) + '-' + (endDateNs.getDate() >= 10 ? endDateNs.getDate() : '0' + endDateNs.getDate())

console.log(defalutStartTime, defalutEndTime)
console 命令行工具 X clear

                    
>
console