Friday, September 20, 2013

Get available TimeZone with java.util.TimeZone

Example to get available TimeZone with java.util.TimeZone class.

Get available TimeZone
Get available TimeZone


package java_timezone;

import java.util.TimeZone;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class Java_TimeZone {

    public static void main(String[] args) {
        System.out.println("Default TimeZone: " + 
                TimeZone.getDefault().getDisplayName());
        
        String[] availableIDs = TimeZone.getAvailableIDs();
        System.out.println("number of available TimeZone IDs: " + 
                availableIDs.length);
        
        for (String id : availableIDs){
            System.out.println(
                    "ID: " + id + 
                    " | " + TimeZone.getTimeZone(id).getDisplayName());
        }
    }
}

No comments:

Post a Comment