我添加了从 2016 年 2 月 19 日开始的 11 天,添加 11 天后,它变成了 2016 年 3 月 1 日,但是当我运行 getMonth() javascript 函数时,它返回二月而不是三月
这是我的代码
var stDate = new Date($("#datepicker1").val());
//Fri Feb 19 2016 00:00:00 GMT+0500 (Pakistan Standard Time)
var secondSeasonDays = stDate.setDate(stDate.getDate() + firstSeasonDays);
//firstSeasonDays = 11
var secondSeasonDays = new Date(secondSeasonDays);
// it return Tue Mar 01 2016 00:00:00 GMT+0500 (Pakistan Standard Time)
var secondSeasonDays = secondSeasonDays.getDate();
var secondSeasonMonth = secondSeasonDays.getMonth();
alert("second season start date is " + secondSeasonDays + " and start month is " + secondSeasonMonth );
// it alerts second season start date is 1 and start month is 2
而 SecondSeasonDaysHere 变量中的日期是 Tue Mar 01 2016 00:00:00 GMT+0500 ,而不是为什么它返回月份为 2 任何建议都会有帮助,提前致谢
最佳答案
The getMonth() method returns the month in the specified date according to local time, as a zero-based value (where zero indicates the first month of the year). The value returned by getMonth() is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.
var months = [ "January", "February", "March", "April" .. ];
关于javascript 添加迄今为止的天数,但它显示旧日期月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35509366/