views:

174

answers:

2

I am trying to parse a date and I am getting different results when I run the code locally/BST compare to a server in Paris/CEST.

I've reproduced the issue in a the following sample. This is trying to parse the start date for the Australian Grand Prix.

    TimeZone tz = TimeZone.getTimeZone("AET");
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH mm");
    dateFormat.setTimeZone(tz);
    long time = dateFormat.parse("28/03/2010 17 00").getTime();
    System.out.println("Time "+time);

It seems like I am setting the timezone correctly on the date format and the current timezone shouldn't be affecting the code. But locally it prints 1269756000000 and in Paris 1269759600000. Any idea?

Answer:

It seems like I was testing with an edge case: the Timezone definition is different on my mac compare to the linux server. If I change the timezone to be: "America/Los_Angeles" I am getting a consistent result. The linux box giving me the wrong result is running java 1.6.0-b105 which might be outdated. I'll try an upgrade

+1  A: 

Interesting. According to the TimeZone documentation:

Three-letter time zone IDs For compatibility with JDK 1.1.x, some other three-letter time zone IDs (such as "PST", "CTT", "AST") are also supported. However, their use is deprecated because the same abbreviation is often used for multiple time zones (for example, "CST" could be U.S. "Central Standard Time" and "China Standard Time"), and the Java platform can then only recognize one of them.

It would be interesting to see the results if you use "Australia/Melbourne" instead of "AET", but just from a quick experiment that I did, it doesn't seem like it makes a difference.

It's curious that the results are an hour apart, like Daylight Savings Time isn't being taken into account in one of the cases. Stupid question; if you're running on two separate computers, are you sure the times are set correctly on each?

Rob Heiser
I tried to use "Australia/Melbourne" but I am getting the same result. Your stupid question is not stupid: I know my server in Paris in something like 10min in advance but that shouldn't make any difference in the code I am running.
Julien Gagnet
+1  A: 

On my system here, the result is "1269756000000" (like on your local system). I would try to check the server in Paris, especially the settings that concern the timezone:

System.out.println(System.getProperty("user.timezone"));
System.out.println(System.getProperty("user.country"));

Maybe this brings up some differences that helps you to solve this issue.

pitpod