获取当前时间
getNowDate(){const timeOne = new Date()
const year = timeOne.getFullYear()
let month = timeOne.getMonth() + 1
let day = timeOne.getDate()
month = month < 10 ? '0' + month : month
day = day < 10 ? '0' + day : day
const NOW_MONTHS_AGO = `${year}-${month}-${day}`
return NOW_MONTHS_AGO
}
num为获取指定日期前多少天的数值,time为null时,默认为当天
getBeforeDate(num, time){
let n = num;
let d = '';if(time){
d = new Date(time);}else{
d = new Date();}
let year = d.getFullYear();
let mon = d.getMonth() + 1;
let day = d.getDate();if(day <= n){if(mon > 1){
mon = mon - 1;}else{
year = year - 1;
mon = 12;}}
d.setDate(d.getDate() - n);
year = d.getFullYear();
mon = d.getMonth() + 1;
day = d.getDate();
let s = year + "-" + (mon < 10 ? ('0' + mon): mon) + "-" + (day < 10 ? ('0' + day): day);
return s;}