在MongoDB中存储日期而不考虑时区 [英] Store date in MongoDB without considering the timezone
问题描述
哪种方法可以在不考虑时区的情况下在MongoDB中存储日期?
Which is the best way to store a date in MongoDB without considering the timezone?
我尝试用一个例子解释问题:
I try to explain the problem with an example:
意大利的Giuseppe在日期2014年12月15日
创建了一个invoce,当系统存储此日期时,将存储在MongoDB中code>2014-12-14T23:00:00.000Z。
Giuseppe in Italy created an invoce in date "December 15, 2014"
, when the system store this date, in MongoDB will be stored "2014-12-14T23:00:00.000Z"
.
英国的John阅读发票并查看2014年12月14日
作为发票日期。
John in UK read the invoice and see "December 14, 2014"
as the invoice date.
显然这些信息是错误的,因为Jhon也应该看到2014年12月15日
作为发票日期,我该如何解决这个问题?
Obviously this information is wrong becouse also Jhon should see "December 15, 2014"
as the invoice date, how can I solve this problem?
推荐答案
整个日期不应放在日期
对象中。尽管名称,日期
表示日期和时间。如果您使用的值代表整个日期,而不是该日期的特定时间,那么您应该以另一种格式存储该值。
Whole dates should not be placed in a Date
object. Despite the name, Date
represents a date and a time. If the value you're working with represents a whole date, rather than a specific time on that date, then you should store the value in another format.
选项包括:
-
YYYY-MM-DD
中的字符串>或YYYYMMDD
格式 - 自某个参考点以来整数天的整数。
- A string in
YYYY-MM-DD
orYYYYMMDD
format - An integer number of whole days since some reference point.
这篇关于在MongoDB中存储日期而不考虑时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!