SimpleDateFormat yields inconsistent results

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

I reproduced the problem in the following example. This is trying to make out the start date of 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 that I have correctly set the time zone in the date format, and the current time zone should not affect the code. But locally he prints 1269756000000 and in Paris 1269759600000. Any idea?

Answer:

It looks like I tested using the edge case: the time zone definition is different from my mac compared to the Linux server. If I change the time zone: "America / Los_Angeles", I get a consistent result. The linux box giving me the wrong result launches java 1.6.0-b105, which may be deprecated. I will try the update

+3
source share
2 answers

Interesting. According to the documentation TimeZone:

. JDK 1.1.x, ( "PST", "CTT", "AST" ) . , (, "" . " " " " ), Java .

, "/" "AET", , , , .

, , Daylight Savings Time . ; , , ?

+2

"1269756000000" (, ). , , :

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

, , .

+1

Source: https://habr.com/ru/post/1739261/


All Articles