简体   繁体   中英

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?

When I convert it into json, what will be displayed? Will it be a large number like unix time stamp or what?

The documentation says it's a UTC DateTime. So expect it to be a string such as: 2010-10-28T23:07:11Z

Best to use mongos native JavaScript Date objects.

You can convert date objects to and from Unix timestamps using 'getTime()' method or 'Date(milliseconds)'

Remember the JavaScript Date object is measured in milliseconds due to the the Unix epoch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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