[英]Java, Hibernate, MySQL - store UTC date-time
I saw here on SO a few related questions (like this one and of course, this one )... Essentially, what I want is to store date-time as UTC, and let application user choose the time zone he wants to display date-time in. 我在这里看到了一些相关的问题(例如这个 ,当然还有这个 )……本质上,我想要的是将日期时间存储为UTC,并让应用程序用户选择他想显示日期的时区时间。
Since it seems that date-time fields are affected by the underlying JDBC driver, I wonder if this is an acceptable way to go about storing UTC date-time: 由于日期时间字段似乎受到底层JDBC驱动程序的影响,所以我想知道这是否是可以接受的存储UTC日期时间的方法:
DATETIME
table columns on MySQL side 在MySQL端使用DATETIME
表列 java.util.Date
as corresponding mapping on Hibernate side (I guess java.sql.Timestamp
could be used too) 使用java.util.Date
作为Hibernate端的对应映射(我想也可以使用java.sql.Timestamp
) Is this OK? 这个可以吗?
EDIT 编辑
To clarify - here I meant to refer to timestamps created strictly on the server (egdate-time of record creation). 为了澄清-这里我指的是严格在服务器上创建的时间戳(例如,记录创建的日期)。 So the application server instantiates Date
objects (new Date() equals current date-time on the server, and this is really time zone agnostic). 因此,应用程序服务器实例化Date
对象(新的Date()等于服务器上的当前日期时间,这实际上是时区不可知的)。
Now if a client user wants to supply some date for searching/filtering purposes, here is where the transformation from client-local time to UTC should take place, IMHO... 现在,如果客户用户想要提供一些日期以进行搜索/过滤,则应在此处进行从客户本地时间到UTC的转换,恕我直言...
I would suggest another simple approach which would independent of machine timezone settings. 我建议另一种简单的方法,该方法与计算机时区设置无关。
set JAVA_OPTS=%JAVA_OPTS% -Duser.timezone=GMT
使用locales
来实现国际化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.