Add one day to date in javascript

后端 未结 8 1313
再見小時候
再見小時候 2020-12-14 06:00

I am sure that a lot of people asked this question but when I checked the answers it seems to me that they are wrong that what I found

var startDate = new Da         


        
8条回答
  •  清歌不尽
    2020-12-14 06:08

    Note that Date.getDate only returns the day of the month. You can add a day by calling Date.setDate and appending 1.

    // Create new Date instance
    var date = new Date()
    
    // Add a day
    date.setDate(date.getDate() + 1)
    

    JavaScript will automatically update the month and year for you.

    EDIT:
    Here's a link to a page where you can find all the cool stuff about the built-in Date object, and see what's possible: Date.

提交回复
热议问题