美文网首页
MongoDB开发之 日期类型

MongoDB开发之 日期类型

作者: 五月笙 | 来源:发表于2020-12-18 09:06 被阅读0次

MongoDB存储时间类型数据时,都是先转换为UTC时间,然后存储到数据库中。

Date objects are stored as a signed 64-bit integer representing the number of milliseconds since the Unix epoch (Jan 1, 1970).

日期类型

  • Date()
    显示当前时间
  • new Date()
    构建一个格里尼治时间,与我们的时区相差+8小时
  • ISODate()
    也是格林尼治时间
> Date()
Thu Dec 17 2020 10:43:48 GMT+0800 (CST)

> new Date()
ISODate("2020-12-17T02:43:56.943Z")

> ISODate()
ISODate("2020-12-17T02:44:01.458Z")

查看类型

> typeof Date()
string

> typeof new Date()
object

时间戳

> ISODate("2020-12-17T02:44:01.458Z").valueOf()
1608173041458

参考

MongoDB Documentation Date
MongoDB权威指南
MongoDB时间类型

相关文章

网友评论

      本文标题:MongoDB开发之 日期类型

      本文链接:https://www.haomeiwen.com/subject/oacxnktx.html