function changeDate (year_add,month_add,day_add) {
let nowTime = new Date();
nowTime.setFullYear(nowTime.getFullYear() + year_add);
nowTime.setMonth(nowTime.getMonth() + month_add);
nowTime.setDate(nowTime.getDate() + day_add);
let nowYear = nowTime.getFullYear();
let nowMonth = nowTime.getMonth()+1;
let nowDay = nowTime.getDate();
if(nowMonth < 10){
nowMonth = "0" + nowMonth;
}
if(nowDay < 10){
nowDay = "0" + nowDay;
}
return nowYear + '-' + nowMonth + '-' + nowDay;
}
console.log(changeDate(0,0,0)); //2020-02-21
console.log(changeDate(1,1,1)); //2021-03-22
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论