蒙戈错误的日期
为什么 mongoDB 为我创建了错误的日期。
> start=new Date(2011,12,23)
"Mon Jan 23 2012 00:00:00 GMT+0000 (UTC)"
> start=new Date(2011,12,24)
"Tue Jan 24 2012 00:00:00 GMT+0000 (UTC)"
> start=new Date(2011,13,24)
"Fri Feb 24 2012 00:00:00 GMT+0000 (UTC)"
> start=new Date(2011,11,24)
"Sat Dec 24 2011 00:00:00 GMT+0000 (UTC)"
>
Why is mongoDB creating wrong dates for me.
> start=new Date(2011,12,23)
"Mon Jan 23 2012 00:00:00 GMT+0000 (UTC)"
> start=new Date(2011,12,24)
"Tue Jan 24 2012 00:00:00 GMT+0000 (UTC)"
> start=new Date(2011,13,24)
"Fri Feb 24 2012 00:00:00 GMT+0000 (UTC)"
> start=new Date(2011,11,24)
"Sat Dec 24 2011 00:00:00 GMT+0000 (UTC)"
>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Mongo的日期对象是Javascript日期对象,它的月份是从0开始的(Jan = 0,Dec = 11)。
除此之外,日历中没有 13 月,因此至少在第三种情况下,您一开始就输入了无效日期 - 只是 JS 规范比较礼貌,并将其翻译为“明年”你认为它完全有效。
Mongo's date object is the Javascript date object, and its months are 0-based (Jan = 0, Dec = 11).
and besides the point, there is no month 13 in the calendar, so in at least the 3rd case, you're feeding an invalid date in to begin with - it's only the JS spec is polite and tranlates that into "next year" for you that it works at all.