javascript - get next day of a string

后端 未结 8 1274
一向
一向 2020-12-16 04:22

I\'ve a var example = \"05-10-1983\"

How I can get the \"next day\" of the string example?

I\'ve try to use Date object...b

8条回答
  •  春和景丽
    2020-12-16 04:27

    You can do the following:

    var nextDay;
    var example = "05-10-1983";
    
    nextDay = new Date(example);
    nextDay.setDate(nextDay.getDate() + 1);
    

    #getDate/#setDate gets/sets the current day of the month (1-31).

    After the above is run, nextDay will be set to whatever tomorrow's date is. This will also rollover to the next month / year if it's the end of the month, and even handle leap years. :)

提交回复
热议问题