Calendar getTimeZone() Method in Java with Examples

The getTimeZone() method in Calendar class is used to return the current time-zone of this Calendar.

Syntax:

public TimeZone getTimeZone()

Parameters: The method does not take any paramters.

Return Value: The method returns timezone of this Calendar object.

Below programs illustrate the working of getTimeZone() Method of Calendar class:
Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to illustrate
// getTimeZone() method
  
import java.util.*;
  
public class Calendar_Demo {
    public static void main(String args[])
    {
        // Creating a calendar object
        Calendar calndr = Calendar.getInstance();
  
        // Getting the time zone of calendar
        TimeZone time_zone = calndr.getTimeZone();
  
        // Displaying the current time zone
        System.out.println("The current Time zone is: "
                           + time_zone.getDisplayName());
    }
}

chevron_right


Output:

The current Time zone is: Coordinated Universal Time

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to illustrate
// getTimeZone() method
  
import java.util.*;
  
public class Calendar_Demo {
    public static void main(String args[])
    {
        // Creating a calendar object
        Calendar calndr = Calendar.getInstance();
  
        // Getting the time zone of calendar
        TimeZone time_zone = calndr.getTimeZone();
  
        // Displaying the current time zone
        System.out.println("The current Time zone is: "
                           + time_zone.getDisplayName());
  
        // Changing the time zone
        calndr.setTimeZone(
            TimeZone.getTimeZone("GMT"));
  
        System.out.println("New TimeZone: "
                           + calndr.getTimeZone()
                                 .getDisplayName());
    }
}

chevron_right


Output:

The current Time zone is: Coordinated Universal Time
New TimeZone: Greenwich Mean Time

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getTimeZone–



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.