Download source code of this article.

Recently in one of my project, time has to be displayed in different time zone. I used the class SimpleDateFormat class to convert and format the local time. This class has one convenient method setTimeZone, which converts the location time to the given time zone while formatting. The following code snippet converts the local time to another time zone:

SimpleDateFormat format = new SimpleDateFormat("EEE, MMM d, yyyy h:mm a");
format.setTimeZone(timezone);
format.format(new Date());

If you want to enumerate all the time zones, you can use the method getAvailableIDs of the TimeZone class. The method returns an array of string which contains all the timezone ids. The sample application lists all the time zones and the corresponding time.