2 Replies Latest reply on Dec 22, 2006 9:51 AM by 807607

    java.util.Date and Daylight Savings

      Maybe I'm worrying too much on this, but I'm conscerned about how well java handles the platform changing over for Daylight Savings... I understand that it reflects UTC, but will this ignore the OS handling of daylight savings? More specifically, when running on Windows (specifcally server 2000), will I lose or gain an hour over daylight savings because of how it translates the time from the OS, or is it safe to assume that it will give me an accurate UTC measurement (less than a minute does not really matter in this case)?
        • 1. Re: java.util.Date and Daylight Savings
          DST is properly handled by Java's TZ classes. (Note, though that TZ rules an can and do change--google for 2007 daylight time or somesuch, for a timey example), but if you've got the up-to-date TZ classes with the current rules, you're good to go.
          • 2. Re: java.util.Date and Daylight Savings
            Date always hold the number of milliseconds since the epoch (1/1/1970 UTC). It has no concept of TimeZone or Daylight Saving or Leap Years/Seconds.

            Calendar and SimpleDateFormat know all about TimeZone and Daylight Saving and Leap Years/Seconds. SimpleDateFormat takes them into account when formatting and parsing. GregorianCalendar takes them into account when you extract field values.

            Date always reflects the true time and is not concerned with how Windows treats the date/time. It does not loose or gain an hour when Daylight Saving kicks in or out but Calendar and SimpleDateFormat handle the change in displayed values.