Add One Month to a Date in JavaScript

后端 未结 2 1457
无人及你
无人及你 2020-12-09 10:21

I have an input field that needs to be incremented by one month using the JavaScript Date object. Below is an example of an effort I have made in incrementing the month. T

2条回答
  •  天命终不由人
    2020-12-09 10:28

    You'll have to get the text out of the text box, which you can then pass to the Date() constructor:

    var d = new Date(text);

    Then format the date string:

    var str = d.getDate(), d.getMonth() + 1, d.getFullYear()

    And set the test box to that value

提交回复
热议问题