nag said:
Does java handle DST automatically ?
I'm using java Gregorian calendar to get the time/date. Does this
automatically give the local time/date iirrespective of DST or special
handling should be done ?
What do you really want to do? If you need to represent a point in time
internally in your application, then a calendar is a bad choice. Use a
Date() object, or the time (as a long, in milliseconds). Java keeps its
date/time in milliseconds since Jan .1st, 1970 00:00 GMT. Only when you
you do some I/O you should consider if you want to have GMT/UTC
date/time, or local time (with DST)
E.g. if you just need to print out some time, [Simple]DateFormat is
often a much better choice than a calendar. It takes the local time-zone
into account, and you an specify another zone. Time-zone information
contains DST information.
A calendar is useful for presenting(!) some point in time in, guess
what, calender format, and doing some calculations based on this
representation, but not more. The representations produced by
GregorianCalender are somewhat imprecise. E.g. GregorianCalendar doesn't
know about leap seconds.
GregorianCalender does take time-zone information (and thus DST, if
defined for a time-zone) into account. But if I remember correctly, does
so inconsistently. If I remember correctly, then it sometimes assumes a
change from/to DST happens at midnight local time, which is wrong for
several time-zones. GregorianCalender also has a problem with the times
which appear twice when the clock is turned back at the end of DST. You
can't specify if you want to have the A (DST) or B (standard) time when
you e.g. set the HOUR value, or when you move into that period with and
add().
Doing timekeeping with a calender is usually a bad idea in Java.
/Thomas