Java Utility Library

Java TimeZone - getTimeZone() Method



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

Syntax

public static TimeZone getTimeZone(ZoneId zoneId)

Parameters

zoneId Specify a ZoneId from which the time zone ID is obtained.

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

import java.util.*;
import java.time.*;  

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

    //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="Asia/Kolkata",offset=19800000,dstSavings=0,useDaylight=false,transitions=7,lastRule=null]

❮ Java.util - TimeZone