問題:
This question already has an answer here: 這個問題在這裏已有答案:
- JavaScript function to add X months to a date 17 answers JavaScript函數將X個月添加到日期 17個答案
I want to add months to a date in JavaScript. 我想在JavaScript中添加幾個月的日期。
For example: I am inserting date 06/01/2011
(format mm/dd/yyyy
) and now I want to add 8 months to this date. 例如:我正在插入日期06/01/2011
(格式mm/dd/yyyy
),現在我想在這個日期添加8個月。 I want the result to be 02/01/2012
. 我希望結果是02/01/2012
。
So when adding months, the year may also increase. 因此,當添加月份時,年份也可能會增加。
解決方案:
參考一: https://en.stackoom.com/question/NgXK參考二: https://stackoom.com/question/NgXK