[ Back | Previous | Next ]

What TimeZones are there and how to use them?

Package:
java.util.*
Product:
JDK
Release:
1.1.x
Related Links:
Calendar
EventObject
Hashtable
Locale
Properties
PropertyResourceBundle
TimeZone
Comment:
To have a correct timestamp we must use the java.util.TimeZone utility. 
But how to use it in conjuction with the java.text.SimpleDateFormat? 
Also what TimeZone representations are out there?

This program will list all the TimeZone ID's:

      String [] ids = TimeZone.getAvailableIDs();
      for (int i=0; i

And here is how to use it in a SimpleDateFormat class:

      sdf = new SimpleDateFormat ("dd/MMM/yyyy:hh:mm:ss zzz");
      sdf.setTimeZone( TimeZone.getTimeZone("ECT") );
      System.out.println( sdf.format( new Date() ) );
 
Will print [01/May/1998:04:07:37 GMT+02:00]