20 lines
985 B
JavaScript
20 lines
985 B
JavaScript
//常用时间 /start 距离当前时间几天前,later往前延续几天
|
|
let getDateLater = function(start=0,later=0) {
|
|
return new Promise(function (resolve, reject) {
|
|
let dateArr = [];
|
|
let date = new Date();
|
|
date.setDate(date.getDate() - start);
|
|
let todate = date.getFullYear() + "-" + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth()+1) + "-" + (date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate());
|
|
date.setDate(date.getDate() - later);
|
|
let laterdate = date.getFullYear() + "-" + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth()+1) + "-" + (date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate());
|
|
let laterMonth = date.getFullYear() + "-" + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth()+1);
|
|
dateArr.push(laterdate)
|
|
dateArr.push(todate)
|
|
dateArr.push(laterMonth)
|
|
resolve(dateArr);
|
|
})
|
|
}
|
|
|
|
module.exports = {
|
|
getDateLater,
|
|
} |