// 获取前几天天的日期 export function getDate(num) { var date1 = new Date() // 前一天的时间 var time1 = date1.getFullYear() + '-' + ((date1.getMonth() + 1) < 10 ? '0' + (date1.getMonth() + 1) : (date1.getMonth() + 1)) + '-' + (date1.getDate() < 10 ? '0' + date1.getDate() : date1.getDate()) var date2 = new Date(date1) date2.setDate(date1.getDate() + num) // num是正数表示之后的时间,num负数表示之前的时间,0表示今天 var time2 = date2.getFullYear() + '-' + ((date2.getMonth() + 1) < 10 ? '0' + (date2.getMonth() + 1) : (date2.getMonth() + 1)) + '-' + (date2.getDate() < 10 ? '0' + date2.getDate() : date2.getDate()) return [time2, time1] } // 两个时间差 export function dateDiffer(d1, d2) { const _d1 = Date.parse(d1) const _d2 = Date.parse(d2) const dateDiffer = Math.abs(_d1 - _d2) const differDay = Math.floor(dateDiffer / (24 * 3600 * 1000)) + 1 return differDay }