开发者

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:

  • When saving a date field in a database, it is timezone agnostic (e.g. always saves in UTC)
  • When using a Java Date object the date it is also timezone agnostic
  • Tim开发者_如何学编程e zone is depeneded only when formatting and parsing dates (DB and Java)
  • If using Java - it will use the JVM user.timezone to format / parse dates
  • If using Java on Windows - Java will take this from the Regional settings automatically
  • The database timezone (and it's machine's timezone) is irrelevant to the Java JDBC client
  • The timezone of the Database Server is relevant only for direct SQL parsing and formating

My questions are:

  1. Are all of the above assumptions correct? some are? all incorect?
  2. Is there a reference / official source that verifies this more "officially"?


The assumption are mostly correct for Java. They are not necessarily correct for databases, as there are variations.

Java handles time zones with Calendar objects. The java.util.Date object always contains the UTC value.

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.

Some databases have the TIMESTAMP WITH TIMEZONE data type which stores both the timestamp and the time zone separately.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜