javascript 在moment.js 中得到错误的月份

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20094812/
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-10-27 17:41:21  来源:igfitidea点击:

Getting wrong month in moment.js

javascriptmomentjs

提问by Ladislav M

I'm using Moment.js included through RequireJS. When I call Moment().month(), instead of number 11 I always get number 10. Any ideas how can this happen?

我正在使用 RequireJS 中包含的 Moment.js。当我打电话时Moment().month(),我总是得到 10 号而不是 11 号。有什么想法怎么会发生?

回答by Gnagy

According to the documentation, months are zero indexed. So January is 0 and December is 11. moment().month() would give the zero based index of the current month (November) which is 10.

根据文档,月份的索引为零。所以一月是 0,十二月是 11。moment().month() 将给出当月(11 月)的零基索引,即 10。