0

We have the problem, that we are receiving a time object definded in local time - with DST. Now we store the receive-time in the database as a DST-less timezone. Once in a year we have one hour where the conversion in not correct: at 2:00AM the clock will be set to 1:00AM in the incoming DST timezone (switching time to winter-time). We correct that to 2AM in local time (i.e. GMT). At 2:15AM we receive a packet which we correct again to 2:15. But now its really 2:15 and not 1:15. In principle we have doubled hour in the system now. The java gregorian calendar is not able to convert between timezones with accounting the current local tim (to determine if it must account for the doubled hour).

Here is my code to convert the incoming DST timezone to the non-DST one:

public static GregorianCalendar getCal(XMLGregorianCalendar c)
{

    GregorianCalendar toGregorianCalendar = c.toGregorianCalendar();
    TimeZone tz = TimeZone.getTimeZone("GMT+1");

    toGregorianCalendar.setTimeZone(tz);
    toGregorianCalendar.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));

    return toGregorianCalendar;
}

This seems to work ok for all the year - except the onle hour switching back to winter-time... Any idea about this mind bending problem?

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Obiwan007
  • 646
  • 1
  • 8
  • 20
  • I don't understand the problem. You are being sensible by storing the time as GTM/UTC. Does it matter what that time was in the original timezone? – Duncan Jones Nov 13 '12 at 12:45
  • 2
    This sounds like a problem with ambiguous input, not with your code. There are two distinct points in time that are both called 1:15, and if the input doesn't specify which one it means, your code has no reliable way to figure it out. – Wyzard Nov 13 '12 at 12:56
  • Perhaps this one could be helpful: [http://stackoverflow.com/questions/13235191/mysql-how-to-store-time-with-correct-timezone-from-java](http://stackoverflow.com/questions/13235191/mysql-how-to-store-time-with-correct-timezone-from-java) – mxns Nov 13 '12 at 13:12

0 Answers0