Home » java.util.TimeZone

java.util.TimeZone

by Online Tutorials Library

Java TimeZone Class

Java TimeZone class represents a time zone offset, and also figures out daylight savings. It inherits the Object class.

Java TimeZone class declaration

Let’s see the declaration of java.util.TimeZone class.

Methods of Java TimeZone

Method Description
static String[] getAvailableIDs() It is used to get all the available IDs supported.
static TimeZone getDefault() It is used to get the default TimeZone for this host.
String getDisplayName() It is used to return a name of this time zone suitable for presentation to the user in the default locale.
String getID() It is used to get the ID of this time zone
int getOffset(long date) It is used to return the offset of this time zone from UTC at the specified date.
void setID(String ID) It is used to set the time zone ID

Java TimeZone class Example: getAvailableIDs()

FileName: TimeZoneExample1.java

Test it Now

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 ....  

Java TimeZone class Example: getOffset()

FileName: TimeZoneExample2.java

Test it Now

Output:

The Offset value of TimeZone: 19800000  

Java TimeZone class Example: getID()

FileName: TimeZoneExample3.java

Test it Now

Output:

Value of ID is: Asia/Kolkata  

Java TimeZone class Example: getDisplayName()

FileName: TimeZoneExample4.java

Test it Now

Output:

Display name for default time zone: India Standard Time  

Java TimeZone class Example: getDefault()

Let’s see the working of the getDefault() method.

FileName: GetDefaultExample.java

Output:

The ID of the default TimeZone is: GMT  

Java TimeZone class Example: setID()

Let’s see the working of the setID() method.

FileName: SetIDExample.java

Output:

The Time zone ID is: GMT + 07:01  

Next TopicJava DateFormat

You may also like