简体   繁体   English

如果我将日期作为日期时间存储在mongodb中,如何在json中显示日期?

[英]If I store date in mongodb as datetime, how do I display the date in json?

What would be the type of the variable returned if the type of variable in mongodb is datetime? 如果mongodb中的变量类型为datetime,返回的变量的类型是什么?

When I convert it into json, what will be displayed? 当我将其转换为json时,将显示什么? Will it be a large number like unix time stamp or what? 会不会像Unix时间戳这样的大量数字?

The documentation says it's a UTC DateTime. 该文档说这是一个UTC日期时间。 So expect it to be a string such as: 2010-10-28T23:07:11Z 因此,期望它是一个字符串,例如: 2010-10-28T23:07:11Z

Best to use mongos native JavaScript Date objects. 最好使用mongos本机JavaScript Date对象。

You can convert date objects to and from Unix timestamps using 'getTime()' method or 'Date(milliseconds)' 您可以使用“ getTime()”方法或“ Date(milliseconds)”(日期(毫秒))在Unix时间戳之间来回转换日期对象。

Remember the JavaScript Date object is measured in milliseconds due to the the Unix epoch. 请记住,由于Unix时代的原因,JavaScript Date对象的测量单位是毫秒。

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

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