简体   繁体   English

mongodb和nodejs中的不同日期

[英]Different date in mongodb and nodejs

Mongo's Date is differ from system and nodeJS date settings. Mongo的日期与系统日期和nodeJS日期设置不同。 How can I fix that? 我该如何解决?

mongo: 蒙哥:

> new Date()
ISODate("2014-06-23T08:53:45.585Z")
> exit
bye

Debian system: Debian系统:

root@vm85820:/var/node/mrandom.com# date

Mon Jun 23 12:54:14 MSK 2014

node: 节点:

root@vm85820:/var/node/mrandom.com# node
> new Date()
Mon Jun 23 2014 12:54:24 GMT+0400 (MSK)

They are not different. 他们没有什么不同。 The MongoDB time is in UTC, the other one in MSK timezone (+4 hours). MongoDB时间为UTC,另一个为MSK时区(+4小时)。

The dates are the same, but MongoDB shell displays the time in UTC format (using ISODate wrapper). 日期是相同的,但是MongoDB shell以UTC格式(使用ISODate包装器)显示时间。 In MongoDB shell, when you use new Date() it will create a new Date object using ISODate wrapper, but if you use just Date() it will return current date as string. 在MongoDB Shell中,当您使用new Date() ,它将使用ISODate包装器创建一个新的Date对象,但如果仅使用Date() ,它将以字符串形式返回当前日期。

> Date()
Mon Jun 23 2014 11:08:05 GMT+0200 (CEST)

You can also convert the Date object to string using toTimeString method: 您还可以使用toTimeString方法将Date对象转换为字符串:

> new Date().toTimeString()
11:08:05 GMT+0200 (CEST)

Internally, MongoDB stores Date objects as a 64 bit integers that represent the number of milliseconds since the Unix epoch. 在内部,MongoDB将Date对象存储为64位整数,代表自Unix纪元以来的毫秒数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM