为什么这个月份不同
下面的代码:
var unixDate = new Date('07/28/2010');
var unixMonth = unixDate.getMonth();
var unixDay = unixDate.getDate();
var unixYear = unixDate.getFullYear();
alert(filterDate.value);
alert(unixMonth);
alert(unixDay);
alert(unixYear);
应该给我 07 月,但它提醒 06.... 为什么会这样?
The following code below:
var unixDate = new Date('07/28/2010');
var unixMonth = unixDate.getMonth();
var unixDay = unixDate.getDate();
var unixYear = unixDate.getFullYear();
alert(filterDate.value);
alert(unixMonth);
alert(unixDay);
alert(unixYear);
should give me month 07 but it alerts 06.... why's that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
月份是从零开始的。只需执行
+1
即可。另请参阅 MDC 的Date.getMonth()
:Months are zero based. Just do
+1
. See alsoDate.getMonth()
at MDC:月份从 0 开始,0=一月
http://www.w3schools.com/jsref/ jsref_getMonth.asp
The months are 0-based, 0=January
http://www.w3schools.com/jsref/jsref_getMonth.asp
.getMonth
返回零索引月份。因此,0 = 一月,11 = 十二月。.getMonth
returns a zero indexed month. So, 0 = January, and 11 = December.使用:
.getMonth
返回零索引月份。更多信息
Use:
.getMonth
returns a zero indexed month.More Info
我的猜测是 0 = 一月,因此您的枚举略有偏差。
My guess would be that 0 = January and thus your enumeration is slightly off.