Java Utility Library

Java Calendar - getTimeZone() Method



The java.util.Calendar.getTimeZone() method is used to get the time zone.

Syntax

public TimeZone getTimeZone()

Parameters

No parameter is required.

Return Value

Returns the time zone object associated with this calendar.

Exception

NA.

Example:

In the example below, the java.util.Calendar.getTimeZone() method is used to get the time zone.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a Calendar object with specified date
    Calendar Cal = new GregorianCalendar(2015, 10, 25);

    //printing the Calendar
    System.out.println("The Calendar is: " + Cal.getTime());

    //printing the time zone
    TimeZone t = Cal.getTimeZone();
    System.out.println("Time Zone: " + t.getDisplayName());
  }
}

The output of the above code will be:

The Calendar is: Wed Nov 25 00:00:00 UTC 2015
Time Zone: Coordinated Universal Time

❮ Java.util - Calendar