methods{
//时间解析
Time(now) {
let year=new Date(now).getFullYear();
let month=new Date(now).getMonth()+1;
let date=new Date(now).getDate();
if (month < 10) month = "0" + month;
if (date < 10) date = "0" + date;
return year+"-"+month+"-"+date
},
//获得某月的天数:
getMonthDays:function (myMonth){
let monthStartDate = new Date(new Date().getFullYear(), myMonth, 1);
let monthEndDate = new Date(new Date().getFullYear(), myMonth + 1, 1);
let days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
return days;
}
}
//用法: 比如 获取上月的数据(其余的情况 自己根据方法修改即可)
let startTime=this.Time(new Date(new Date().getFullYear(),new Date().getMonth()-1,1));
let endTime=this.Time(new Date(new Date().getFullYear(),new Date().getMonth()-1,this.getMonthDays(new Date().getMonth()-1)));