js 指定日期添加天数自动变为下年或下月

【js 指定日期添加天数自动变为下年或下月】代码如下

let date = '2021-12-02', n = 2; let dateOne = new Date(date.replace('-', '/')); let time = dateOne.getTime() + n * 24 * 3600 * 1000; let dateTwo = new Date(time); let startTime = dateTwo.getFullYear() + '-' + (dateTwo.getMonth() + 1) + '-' + dateTwo.getDate() console.log(startTime)//startTime --> 2021-12-04

    推荐阅读