views:

258

answers:

2

We have seen a strange issue on some Windows XP machines involving the "Co-ordinated Universal Time" time zone. Not all Windows XP machines seem to have it, but on those that do, the following simple Java program

public class TimeTest {
    public static void main(String[] args) {
        System.out.println(java.util.TimeZone.getDefault());
        System.out.println(new java.util.Date());
    }
}

on JDK 1.6.0_06 prints:

sun.util.calendar.ZoneInfo[id="America/Caracas",offset=-16200000,dstSavings=0,useDaylight=false,transitions=5,lastRule=null]
Fri Nov 13 05:34:14 VET 2009

(i.e. 4 and a half hours behind GMT). I should add that I am based in London, and have never been to South America. :-)

My questions are:

  • Where does Java get this time zone from? I thought Co-ordinated Universal Time was supposed to be the new name for GMT.
  • Why do some Windows machines have this time zone but not others?
A: 

It's printing out it using the default time zone. Your subject talks about "choosing" UTC, but I don't see any such choice in your program. If you've chosen it somewhere else, please give details of exactly where. If you've changed the XP time zone, you may want to try rebooting - it's possible that your Java code is getting a cached value from somewhere.

Print out java.util.TimeZone.getDefault and I suspect you'll see VET on the machines with the problem.

If you want your code to use UTC, you should specify that explicitly... preferably using Joda Time instead of the built-in Date/Calendar classes.

EDIT: If you have .NET 3.5 on the same machines, try this little program to see what it thinks the time zone is:

using System;

class Test
{
    static void Main()
    {
        Console.WriteLine(TimeZoneInfo.Local.DisplayName);
    }
}
Jon Skeet
By "choosing", I meant selecting it in Control Panel / Date and Time / Time Zone, rather than setting it programmatically. When I change it to other values in Control Panel, Java appears to change its idea of the default time zone, but it seems absurdly off for this value.
Simon Nickerson
Okay, in that case that's very odd. Are all machines (working + not) using the same version of Java?
Jon Skeet
I have only found two Windows XP machines which have the UTC time zone in Control Panel. Both were using 1.6.0_06. Running the same code on 1.5.0_12 gives a different odd time zone! (ACT = America/Rio_Branco, GMT-05)
Simon Nickerson
Moreover, rebooting made no difference.
Simon Nickerson
Consider using the [Java Timezone Update][1] Tool. I guess Java handles the timezone differently from the OS. [1]: http://java.sun.com/javase/tzupdater_README.html
Miguel Ping
A: 

I got the same problem in a Unix/Solaris. The date command use a Time/Zome variable when a comand like these "date -u 042315232010". If you use the parameter -u the comand date use a variable named TZ and it proced to ajust the GMT time against those in TZ. To solve these use the comand "date 042315232010" and all worked. Perhaps you should avoid TimeZone sentences in your Java program. By the way "date 042315232010" means "Fri Apr 23 15:23:00 VET 2010".

ogt