1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| /** * [setNdayDate 获取n天后日期(转格式后的)] * @param {[type]} num [天数] _time [传入时间] */ function setNdayDate(num, _time) { let _this = this; let d = new Date(); if (_time) { d = new Date(_time.replace(/-/g, "/")); } let year = d.getFullYear(); let month = _this.addZero(d.getMonth() + 1); let day = _this.addZero(d.getDate()); let hour = _this.addZero(d.getHours()); let min = _this.addZero(d.getMinutes()); let sec = _this.addZero(d.getSeconds());
//今天 let new_day = year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec; let old_day = new_day; if (num != 0) { //num天后 d.setDate(parseFloat(day) + parseFloat(num)); let old_year = d.getFullYear(); let old_month = _this.addZero(d.getMonth() + 1); old_day = _this.addZero(d.getDate()); let old_hour = _this.addZero(d.getHours()); let old_min = _this.addZero(d.getMinutes()); let old_sec = _this.addZero(d.getSeconds());
old_day = old_year + '-' + old_month + '-' + old_day + ' ' + old_hour + ':' + old_min + ':' + old_sec; } return { new_day: new_day, new_day_str: Date.parse(new_day.replace(/-/g, "/")), old_day: old_day, old_day_str: Date.parse(old_day.replace(/-/g, "/")), } }
|