Incrementing a date in JavaScript

后端 未结 17 2326
余生分开走
余生分开走 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:00

    Get the string value of the date using the dateObj.toJSON() method Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON Slice the date from the returned value and then increment by the number of days you want.

    var currentdate = new Date();
    currentdate.setDate(currentdate.getDate() + 1);
    var tomorrow = currentdate.toJSON().slice(0,10);
    

提交回复
热议问题