Date and Time

How to Date Formatting In Java With Time Zone

Table of Contents

Program

import java.util.Calendar;
import java.util.TimeZone;

public class TimeZone {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String[] id = TimeZone.getAvailableIDs();        
		   System.out.println("In TimeZone class available Ids are: ");  
		   for (int i=0; i<id.length; i++){  
		   System.out.println(id[i]);  
		   }   
		   TimeZone zone = TimeZone.getTimeZone("Asia/Kolkata");   
		   System.out.println("The Offset value of TimeZone: " +   
		  zone.getOffset(Calendar.ZONE_OFFSET));  
		   TimeZone zone1 = TimeZone.getDefault();  
		   String name = zone1.getDisplayName();         
		   System.out.println("Display name for default time zone: "+ name);  

	}

	
}

Output

	In TimeZone class available Ids are: 
	Africa/Abidjan
	Africa/Accra
	Africa/Addis_Ababa
	Africa/Algiers
	Africa/Asmara
	Africa/Asmera
	Africa/Bamako
	Africa/Bangui
	Africa/Banjul
	Africa/Bissau and so on ....
	The Offset value of TimeZone: 19800000
	Value of ID is: Asia/Kolkata

Description

public static String[] getAvailableIDs()

Gets all the available IDs supported.

Returns:

an array of IDs.

public static TimeZone getDefault()

Gets the default TimeZone of the Java virtual machine. If the cached default TimeZone is available, its clone is returned. Otherwise, the method takes the following steps to determine the default time zone.
Use the user.timezone property value as the default time zone ID if it’s available.
Detect the platform time zone ID. The source of the platform time zone and ID mapping may vary with implementation.
Use GMT as the last resort if the given or detected time zone ID is unknown.
The default TimeZone created from the ID is cached, and its clone is returned. The user.timezone property value is set to the ID upon return.

Returns:

he default TimeZone

See Also:

setDefault(TimeZone)

public String getDisplayName()

Gets the localized display name of this feature.

Returns:

The localized display name for the property/method/event.
This defaults to the same as its programmatic name from getName.

public int getOffset()

Returns the offset of the default bank in array elements.

Returns:

the offset of the default bank.

public abstract int getTimezone()

Returns the Timezone offset in minutes or DatatypeConstants.FIELD_UNDEFINED if this optional field is not defined.
Value constraints for this value are summarized in timezone field of date/time field mapping table.

Returns:

The Timezone offset in minutes of this XMLGregorianCalendar.This defaults to the same as its programmatic name from getName.

See Also:

setTimezone(int)