Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Read GMT dates in Java

Read GMT dates in Java

From: gunjeet singh <gunjeet.singh_at_eng.sun.com>
Date: Thu, 29 Nov 2001 15:23:42 -0800
Message-ID: <3C06C37E.B191C7D9@eng.sun.com>

I have a question about storing the dates in GMT in the database and reading
them back through JDBC in a java program.

We have machines in different timezones from which we collect the data and store in a centralized server. The timezone in which you view this data could still be different from the timezone of the machines from where data is collected and the timezone of the server.

Here's what we do :

Assume a machine in EST timezone. If data is collected at 6PM EST and brought over to the server in PST TZ, the data is logged as below :

SQL> select to_char(opened,'DD MON YYYY HH:MI:SSAM') from test where id = 123;

              TO_CHAR(OPENED,'DDMONYYYYHH:

---------- ------------------------- 
	
	      29 NOV 2001 11:00:00PM

Please note that I haven't used any sql functions, simply done a to_char on the stored value.

What we see in the database is the EST time stored in GMT format (6PM EST = 6 + 5 = 11 PM GMT) and it's the same if we were to interpret it as the PST time stored in GMT (3PM PST + 8 = 11 PM GMT).

How should we read it in a Java program ? We currently do a getTimestamp(columnIndx) on the resultset. We then create a java.util.Date object using the ts.getTime() method. It appears that the java date interprets the GMT date/time coming from the database as a PST
date/time and adds another 8 hours to that to return the long value.

We have even tried using a Calender object (with GMT TZ set) while invoking the getTimestamp method but it doesn't help.

Can someone help and explain how we should be reading these dates that are stored in GMT in the database ? Received on Thu Nov 29 2001 - 17:23:42 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US