在不考虑时区的情况下,在 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模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)
XMLHttpRequest 的 getResponseHeader() 的限制?Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)