Add 30 days to date (mm/dd/yy)

后端 未结 4 2092
耶瑟儿~
耶瑟儿~ 2020-12-03 16:59

I have a date in the format mm/dd/yy and want to add 30 days to it. I am just curious the best method to do this? I am new to javascript so examples would be he

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 17:45

    A simple way to get it done is to send the timestamp value in the Date constructor. To calculate 30 days measured in timestamp:

    30 * 24 * 60 * 60 * 1000

    Then, you need the current timestamp:

    Date.now()

    Finally, sum both values and send the result as a param in the constructor:

    var nowPlus30Days = new Date(Date.now() + (30 * 24 * 60 * 60 * 1000));

提交回复
热议问题