Incrementing a date in JavaScript

后端 未结 17 2161
余生分开走
余生分开走 2020-11-22 05:15

I need to increment a date value by one day in JavaScript.

For example, I have a date value 2010-09-11 and I need to store the date of the next day in a JavaScript v

17条回答
  •  悲哀的现实
    2020-11-22 06:01

    Via native JS, to add one day you may do following:

    let date = new Date(); // today
    date.setDate(date.getDate() + 1) // tomorrow
    

    Another option is to use moment library:

    const date = moment().add(14, "days").toDate()
    

提交回复
热议问题