[英]What is the best way of storing date?
I am a new to storing dates based on time zones. 我是一个基于时区存储日期的新手。
Need to know the standard way to store the date in the datastore. 需要知道在数据存储区中存储日期的标准方法。
My requirements are 我的要求是
Any suggestions/ideas regarding this will be a great help in proceeding further. 有关这方面的任何建议/想法将对进一步推进有很大帮助。
Always convert and store data/time in UTC so the data become easily understandable and non-ambiguous 始终以UTC格式转换和存储数据/时间,以便数据易于理解且不含糊
Only convert the date/time back to "local time" of the user for displaying purpose. 仅将日期/时间转换回用户的“本地时间”以进行显示。
It's a good idea to store dates in UTC/GMT equivalent millisecond format. 以UTC / GMT等效毫秒格式存储日期是个好主意。 On the result of which it will be easy to convert back and forth to appropriate time zone based on offset either from UI or server side.
在结果上,根据UI或服务器端的偏移量,可以很容易地来回转换到适当的时区。 I believe date in database should be zone independent to avoid unnecessary complexity.
我相信数据库中的日期应该与区域无关,以避免不必要的复杂性
The best/easy way to handle zone conversation is from UI using JavaScript, as clients side will be always local time. 处理区域对话的最佳/简单方法是使用JavaScript的UI,因为客户端始终是本地时间。 There are multiple JS plugins available to handle this.
有多个JS插件可用于处理此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.