function getDateRange(dateNow,intervalDays,bolPastTime){
let oneDayTime = 24 * 60 * 60 * 1000;
let list = [];
let lastDay;
if(bolPastTime == true){
lastDay = new Date(dateNow.getTime() - intervalDays * oneDayTime);
list.push(this.formateDate(lastDay));
list.push(this.formateDate(dateNow));
}else{
lastDay = new Date(dateNow.getTime() + intervalDays * oneDayTime);
list.push(this.formateDate(dateNow));
list.push(this.formateDate(lastDay));
}
return list;
}
function formateDate(time){
let year = time.getFullYear()
let month = time.getMonth() + 1
let day = time.getDate()
month = month< 10 ?'0' + month:month;
day = day < 10 ? '0' + day:day;
return year + '-' + month + '-' + day
}
//结果
var date = new Date();
var list = this.$getDateRange(date, 30, true) //近一个月
var list = this.$getDateRange(date, 6, true) //近一周
var list = this.getDateRange(date, 0, true) //今天
var list = this.getDateRange(date, 1, true) //昨天
var list = this.getDateRange(date, 6, false) //获取下一周日期范围
var list = this.getDateRange(date, 30, false) //获取下一个月日期范围
默认最近一周