Store date in MongoDB without considering the timezone(在 MongoDB 中存储日期而不考虑时区)
问题描述
在不考虑时区的情况下,在 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 中存储日期而不考虑时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 MongoDB 中存储日期而不考虑时区


基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01