Javascript javascript正在创建日期错误的月份

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12254333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 07:32:19  来源:igfitidea点击:

javascript is creating date wrong month

javascript

提问by Joe Kahl

using Mozilla Firefox Firebug:

使用 Mozilla Firefox Firebug:

var myDate = new Date(2012, 9, 23, 0,0,0,0);
myDate;

Date {Tue Oct 23 2012 00:00:00 GMT-0400 (Eastern Daylight Time)}

日期 {2012 年 10 月 23 日星期二 00:00:00 GMT-0400(东部夏令时间)}

Why does javascript create the date with the wrong month?

为什么javascript会用错误的月份创建日期?

回答by zerkms

No, javascript's Datemonths start with 0, so 9is a 10th month and it is October

不,javascript 的Date月份以 开头09第 10 个月也是 10 月

Reference:

参考

new Date(year, month [, day, hour, minute, second, millisecond]);

[...]

monthInteger value representing the month, beginning with 0 for January to 11 for December.

new Date(year, month [, day, hour, minute, second, millisecond]);

[...]

month表示月份的整数值,从 0 开始表示 1 月到 11 表示 12 月。

回答by Joe Kahl

In the javascript world months begin with zero! kind of weird to me. Anyhow, 9 is NOT September, but rather 9 is October.

在 javascript 世界中,月份从零开始!对我来说有点奇怪。无论如何,9 不是九月,而是 9 是十月。