Java Utility Library

Java TimeZone - getTimeZone() Method



The java.util.TimeZone.getTimeZone() method is used to get the TimeZone for the given ID.

Syntax

public static TimeZone getTimeZone(String ID)

Parameters

ID Specify the ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00".

Return Value

Returns the specified TimeZone, or the GMT zone if the given ID cannot be understood.

Exception

NA

Example:

In the example below, the java.util.TimeZone.getTimeZone() method is used to get the TimeZone for the specified ID.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a TimeZone object
    TimeZone tz = TimeZone.getTimeZone("IST");

    //printing the time zone value
    System.out.println("The TimeZone is:\n" + tz);
  }
}

The output of the above code will be:

The TimeZone is:
sun.util.calendar.ZoneInfo[id="IST",offset=19800000,dstSavings=0,useDaylight=false,transitions=7,lastRule=null]

❮ Java.util - TimeZone