1.求距离某个日期n天后的日期
function a1(dayStr,nums) {
let t1 = new Date(dayStr);
console.log(t1);
let t2 = new Date((t1/1000 + 86400*nums)*1000);
console.log(t2);
var t3 = t2.getFullYear() + '-' + (t2.getMonth() + 1) + '-' + t2.getDate();
console.log(t3);
}
a1('2020-01-03',2);
a1('2020/01/03',28);
2.求两个日期的差值
function a2(day1,day2) {
let t1 = Date.parse(day1);
let t2 = Date.parse(day2);
console.log(t1,t2);
let t3 = t1 > t2?t1-t2:t2-t1;
console.log(t3);
let t4 = t3/(1*24*60*60*1000);
console.log(t4);
}
a2('2020-01-03','2020-01-05');
a2('2020/01/03','2019/12/23');