DST issue: Date discrepancy in displaying the retrieved Date from database

Hope you know the general DST Transition funda.

The DST date time wont be having time 2007 Mar 10 2:00:00 AM. Instead it has 3:00:00 AM. Here the transition takes place from 1:59:99 AM to 3:00:00 AM.

Let me describe my issue in detail.

We have data for 2:00:00AM am and 3:00:00AM separately in the database. The project uses JDK 1.5 version and it has the DST fix. So the Date object of this JDK1.5 wont be having 2:00:00 AM.

Actual problem goes here:

I am trying to retrieve a record with the Date 2:00:00 AM and assigning to the Date variable. The Date object variable is then sent to the reports and displays. Instead of 2:00:00 AM it report has 3:00:00 AM which is a wrong data. We know that Java Date object automatically converts the time to 3:00:00 which is correct as per the DST fix.

In my case, I should show the user the data that is exactly in the database. Is there any generic/global solution for this issue?

Hope I you understand the problem clearly.

[1017 byte] By [Mani_csa] at [2007-11-27 11:47:21]
# 1

Please note that "DST", "Timezone" and stuff like that are display issues only. java.util.Date doesn't know about any of it.

A java.util.Date object represents a 'moment in time', represented as the number of milliseconds since the moment in time we western humans call January 1st, 1970, 0:00:00,000.

As 2:00 AM and 3:00 AM on a DST-switch date represent the exact same moment in time, there is no way for a java.util.Date to know about the distinction.

So if you want to display the distinction for the benefit of the user (I wonder why, but that's your problem), you will have to look outside java.util.Date for a solution. Depending on how your database stores its values, you might be able to retrieve the String representation of the date and work with that.

TBH, I would look at fixing the inconsistencies in the database instead of creating work-arounds for them in your code. But then I don't know your problem domain, perhaps you have a very good reason for having two different representations of the same moment in time.

Herko_ter_Horsta at 2007-7-29 18:12:39 > top of Java-index,Java Essentials,Java Programming...