I found out that when it’s the 31st, 30th, or 29th of a month, setting the date to a month that has a fewer number of days causes getMonth to return the wrong value.推荐答案让我们分解一下:var d = new Date(); // date is now 2013-01-31d.setMonth(1); // date is now 2013-02-31, which is 3 days past 2013-02-28x = d.getMonth(); // what to do, what to do, 3 days past 2013-02-28 is in March // so, expect x to be March, which is 2仅当 d 的天值大于传递给 setMonth() 的月份中的最大天数时,才会出现此问题.否则,它会按您的预期工作.This is only an issue when the day value of d is greater than the maximum number of days in the month passed to setMonth(). Otherwise, it works as you'd expect. 这篇关于如果`date`在月末,`date.setMonth`会导致月份设置得太高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-03 14:17