5 Replies Latest reply: Apr 2, 2008 2:24 PM by 807591 RSS

    java.util.Date and Timezone

    807591
      I am displaying the current date and time by creating a new java.util.Date object and then doing a toString() on it. But since the daylight savings time change a few weeks ago, the time has been an hour off. I am running version 1.6.0_03-b05 on a Xubuntu Linux machine. I have a set of machines that I set up at the same time in the same way, and half of them have this problem with the other half displaying the correct time. Any thoughts on how to fix this? Thanks. -Don
        • 1. Re: java.util.Date and Timezone
          807591
          Java will display the time set on your system.
          I am guessing Ubuntu is not set to use "Automatic Daylight Savings Adjustments" or not set with appropriate "Time Zone".
          Best solution for this would be to setup a NTP server on one of your boxes in your network, and configure rest of machines to
          use this NTP server.
          So you may want to look in to configuring NTP server and Client.
          • 2. Re: java.util.Date and Timezone
            807591
            Thanks for the response. I should have mentioned that I have verified the local system time zone setting and that the local system time is displayed correctly on the clock. I have also tried updating the time zone using the TZupdater tool, but to no avail.
            • 3. Re: java.util.Date and Timezone
              jschellSomeoneStoleMyAlias
              When java starts on a unix box it uses a rather complicated process to determine what the correct timezone is. Windows is a bit simpler although not trivial.

              Whatever that process is it isn't succeeding on your box.

              There is either formal or informal documentation on that process somewhere. But I don't know where.

              You could also figure it out by looking at the source code.
              • 4. Re: java.util.Date and Timezone
                807591
                I don't have Ubuntu. But if you are running the latest version it should have new Tzdata files as per new DayLightSavings time.

                And if I remember correctly the new DayLightSavings is adopted in 1.5 itself. So I am positive the 1.6 will also have it.

                You can check if Linux is set with correct DayLightSavings by running following command. Make sure YOu see Mar 9 and Nov 2
                $ /usr/sbin/zdump -v /etc/localtime  | grep 2008
                • 5. Re: java.util.Date and Timezone
                  807591
                  Yes, I already did the zdump as well and I see the correct dates (3/9 and 11/2 for 2008). It seems the Xubuntu system has the right settings as the time is displayed correctly in the system clock, it's the Java Date part that seems to be getting it wrong.