简体   繁体   English

存储日期的最佳方式是什么?

[英]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 我的要求是

  1. Easy to query the date based on the date range. 可以根据日期范围轻松查询日期。
  2. show the date with the client appropriate time zone selected by him(I am having a table maintained for the timezone separately) 显示他选择的客户端适当时区的日期(我正在为时区分别维护一个表)
  3. Able to query using the datastore Admin console also. 也可以使用数据存储管理控制台进行查询。

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插件可用于处理此问题。

Here is one MomentJS 这是一个MomentJS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在.jar存档中存储和提取文件的最佳方法是什么? - What's the best way of storing and extracting files inside the .jar archive? 在Clojure中获取日期和时间的最佳方式是什么? - What is the best way to get date and time in Clojure? 在Java中比较字符串日期和日期对象的最佳方法是什么? - What is the best way to compare a String date and Date Object in java? 在iOS / Android和Firebase中处理日期的最佳方法是什么? - What is the best way to deal with Date in iOS / Android and Firebase? 在spring boot jpa中存储日期的最佳方法是什么? - What's the best way to store date in spring boot jpa? 增加Java.sql.date / time的最佳方法是什么? - What is the best way to increment a Java.sql.date / time? 在Java Web应用程序中处理图像的最佳方法是什么:存储在Blob字段中还是仅存储在其路径中? - What's the best way to deal with images in a Java web app: storing in Blob fields or just its paths? 在 Java 中,如果一个点位于一组平面内,存储和测试的最佳方法是什么? - In Java, what is the best way of storing and testing if a point lies within a set of planes? 在Android中存储字符串和图像数据的最佳方法? - Best way of storing String and Image data in Android? 储存2D游戏地图的最佳方法 - The best way for storing 2D game map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM