Fog Creek Software
Discussion Board




Java, dates, and time zones

Suppose you have a table (SomeTable), with a date/time field (SomeDate). A query (select * from SomeTable) on that table gives you the following result:

SomeDate
--------
2004-01-01 10:00:00

While investigating a problem in one of our apps, I found out that depending on the time zone of the JVM, the date/time Java shows you may not be the one you have on the DB. So, that means that, e.g., I could fetch SomeTable.SomeDate via JDBC, display it, and get "2004-01-01 11:00:00".

I found a few articles and posts confirming that this is how it works. What I didn't find is the rationale behind this design. I may be missing something, but I see plenty of potential for confusion here, and no advantages.

Could anyone care to enlighten me?

Thanks.

Paulo Caetano
Tuesday, August 10, 2004

Unless the date was stored as UTC or GMT in the database (not a bad thing to do) there's no point trying to enforce locale time zone on it.

However, Time objects in Java are stored as UTC so it may not be the JDBC that's making the assumption but the class you're manipulating it with afterwards.

Simon Lucy
Tuesday, August 10, 2004

What time zone should it be interpretted as?  Local is the only one that makes sense if the TZ isn't in the string.  Normalize all your times to GMT or whatever when they're inserted.

doom 3
Tuesday, August 10, 2004


I'll second that.

GMT is the *only* way to go.

KC
Tuesday, August 10, 2004

Having a bit of trouble here...
What determines the format of the time zone? I'm working with a Java based system (that I'm not yet too familiar with) and I've got one system reporting it's in TZ ECT (+01:00) and another is in TZ Europe/Berlin (+01:00).
Then when I look up ECT it seems to mean Equador time...

What does Java do with the tz code? I've heard of British Summer Time (BST) being confused with Bangladesh Standard Time. There doesn't seem to be an international standard for these codes.

Can anyone explain these things or point me to a good reference site?

Thanx...

Duq
Wednesday, August 25, 2004

*  Recent Topics

*  Fog Creek Home