问题:
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