function getDefaultTime() {
const date = new Date()
// 获取开始日期
const startDate = new Date(date.getTime() - 6 * 24 * 60 * 60 * 1000)
const startYear = startDate.getFullYear()
let startMonth = startDate.getMonth() + 1
startMonth = startMonth <= 9 ? '0' + startMonth : startMonth
let startDay = startDate.getDate()
startDay = startDay <= 9 ? '0' + startDay : startDay
// 结束日期
const year = date.getFullYear()
let month = date.getMonth() + 1
let strDate = date.getDate()
if (month >= 1 && month <= 9) {
month = '0' + month
}
if (strDate >= 0 && strDate <= 9) {
strDate = '0' + strDate
}
return [startYear + '-' + startMonth + '-' + startDay, year + '-' + month + '-' + strDate]
}
该函数用于获取当前日期前六天的开始日期和当前日期,格式化为指定的字符串形式。通过减去六天得到开始日期,并确保月份和日期在一位数时前面补零。返回一个包含开始和结束日期的数组。
956

被折叠的 条评论
为什么被折叠?



