javascript 添加迄今为止的天数,但它显示旧日期月份

标签 javascript datetime

我添加了从 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" .. ];

Source

关于javascript 添加迄今为止的天数,但它显示旧日期月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35509366/

相关文章:

javascript - 是否可以验证给定文本是否为 JavaScript 代码?

javascript - 使用 pg-promise 执行接受参数数组的 Postgresql 函数

python - 在 Python 中添加持续时间

c# - Microsoft 的 .NET GWT 解决方案是什么?

javascript - 返回不包括特定范围的随机数 - javascript

javascript - 在 Javascript 中为 D3 图形声明 CSS 样式

sql-server-2008 - tsql DATEDIFF 在几分钟内调用而不舍入秒数

PHP DateTime::createFromFormat 行为

java - Java/Android 中 Time 类功能的替换以及 DateTime 类的理解

mysql - INSERT 期间的 MSSQL 格式日期和时间