mongodb/mongoose中的日期格式 [英] Date format in mongodb/mongoose

查看:698
本文介绍了mongodb/mongoose中的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在javascript中创建日期时,它在zulu中,当我通过mongoose将其保存在mongodb中时,它将转换为UTC(其保留相同的时间值,但时区已更改).保存后我希望它保留在祖鲁语中,如何在猫鼬中设置此选项?

When I create a date in javascript it is in zulu, when I save it in my mongodb via mongoose it is transformed to UTC (its keeps the same time value, but the timezone is changed). I'd like it to stay in zulu when saved, how can I set this option in mongoose ?

谢谢

推荐答案

MongoDB将所有DateTimes存储在UTC中.存储在数据库中时,您提供的任何本地时间都会转换为UTC.推荐的方法是始终将DateTime值自己转换为UTC,然后再将它们存储在数据库中,这样您就可以完全控制.

MongoDB stores all DateTimes in UTC. Any local times you supply are converted to UTC when stored in the database. The recommended approach is to always convert DateTime values to UTC yourself before storing them in the database, that way you are in full control.

资源:

https://jira.mongodb.org/browse/CSHARP-185
处理MongoDB在使用时如何存储DateTime的方法服务定位器模式

这篇关于mongodb/mongoose中的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆