在不考虑时区的情况下,在 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在日期December 15, 2014"
创建了一个invoce,当系统存储这个日期时,MongoDB中将存储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 在英国阅读了发票并看到 December 14, 2014"
作为发票日期.
John in UK read the invoice and see "December 14, 2014"
as the invoice date.
显然这个信息是错误的,因为 Jhon 也应该看到 "December 15, 2014"
作为发票日期,我该如何解决这个问题?
Obviously this information is wrong becouse also Jhon should see "December 15, 2014"
as the invoice date, how can I solve this problem?
不应将整个日期放在 Date
对象中.尽管有这个名字,Date
代表一个日期和一个时间.如果您正在使用的值表示整个日期,而不是该日期的特定时间,那么您应该以另一种格式存储该值.
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
格式的字符串这篇关于在 MongoDB 中存储日期而不考虑时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!