[英]Request to Verify - How Databases and Java store and handle timezones?
My apologies for the extremely basic question, I think I know the answer but would like to verify: 我对这个非常基本的问题表示道歉,我想我知道答案,但想验证:
When refering to time zones and how they are usually stored in a database and in a java.util.Date: 在引用时区以及它们通常如何存储在数据库和java.util.Date中时:
My questions are: 我的问题是:
The assumption are mostly correct for Java. Java的假设大多是正确的。 They are not necessarily correct for databases, as there are variations. 它们不一定适用于数据库,因为存在变化。
Java handles time zones with Calendar objects. Java使用Calendar对象处理时区。 The java.util.Date object always contains the UTC value. java.util.Date对象始终包含UTC值。
Databases generally store and return dates and timestamps (with hour, minutes, etc.) as they are written, regardless of the internal format used by storage. 无论存储使用何种内部格式,数据库通常会在写入时存储和返回日期和时间戳(包括小时,分钟等)。 If you store 2010-12-25, you will retrieve the same value regardless of the time zone of the clients or server. 如果存储2010-12-25,则无论客户端或服务器的时区如何,都将检索相同的值。
Some databases have the TIMESTAMP WITH TIMEZONE data type which stores both the timestamp and the time zone separately. 某些数据库具有TIMESTAMP WITH TIMEZONE数据类型,它分别存储时间戳和时区。
Dates and timestamps are converted between Java and Database, usually in a manner that the subclasses of java.util.Date that are used are interpreted in the JDBC client's time zone. 日期和时间戳在Java和数据库之间转换,通常以在JDBC客户端的时区中解释所使用的java.util.Date的子类的方式进行转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.