Ganesh
Ganesh

Reputation: 39

Java Timezone Issue

Using Timezone.getTimeZone("Antarctica/Casey"), certain time zones are returning the invalid output. For eg.,

SimpleDateFormat outputFormat = new SimpleDateFormat( "MM/dd/yyyy hh:mm aa zzz" );  
outputFormat.setTimeZone( TimeZone.getTimeZone( "Antarctica/Casey" ) );  
System.out.println(outputFormat.format( new Date() ));  

Which suppose to return "MM/dd/yyyy hh:mm aa CAST", but it returning "MM/dd/yyyy hh:mm aa WST".

Like this here are the few other things having issues,

  1. Australia/Adelaide - ACST / ACDT
  2. Australia/Eucla - ACWST / ACWDT
  3. Australia/Sydney - AEST / AEDT
  4. Antarctica/Mawson - AHMT
  5. Australia/Perth - AWST / AWDT
  6. Pacific/Apia - SST.

Upvotes: 4

Views: 1573

Answers (2)

Wit Mesh
Wit Mesh

Reputation: 21

You need to check your java version: http://www.oracle.com/technetwork/java/javase/7u-relnotes-515228.html

The timezone fix was done in tzdata2014f (http://www.oracle.com/technetwork/java/javase/tzdata-versions-138805.html):

Australian eastern time zone abbreviations are now AEST/AEDT not EST, and similarly for the other Australian zones.

So, to solve this issue, we need to update Java to at least 7u75.

Upvotes: 0

assylias
assylias

Reputation: 328568

If you check the IANA Time Zone Database, you will see that Casey is currently on the WST timezone and has been since February 2012.

# Zone  NAME        GMTOFF  RULES   FORMAT  [UNTIL]
Zone Antarctica/Casey   0   -   zzz 1969
            8:00    -   WST 2009 Oct 18 2:00
                        # Western (Aus) Standard Time
            11:00   -   CAST    2010 Mar 5 2:00
                        # Casey Time
            8:00    -   WST 2011 Oct 28 2:00
            11:00   -   CAST    2012 Feb 21 17:00u
            8:00    -   WST

Here is a more detailed reference to the change: http://www.timeanddate.com/news/time/antarctica-2012.html.

However WST is only used when printing: internally the changes from GMT+8 to GMT+11 are correctly handled. See for example:

public static void main(String[] args) {
  SimpleDateFormat outputFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm aa Z");
  TimeZone tz = TimeZone.getTimeZone("Antarctica/Casey");
  outputFormat.setTimeZone(tz);

  Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

  //May 2014 = GMT + 8
  System.out.println(outputFormat.format(c.getTime()));

  //january 2012 = GMT + 11
  c.set(Calendar.YEAR, 2012);
  c.set(Calendar.MONTH, 0);
  System.out.println(outputFormat.format(c.getTime()));
}

As for the other differences, it is probably the difference between summer and winter time.

Upvotes: 5

Related Questions