Skip to content
Related Articles

Related Articles

Calendar getTimeZone() Method in Java with Examples
  • Last Updated : 06 Mar, 2019

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:






// 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());
    }
}
Output:
The current Time zone is: Coordinated Universal Time

Example 2:




// 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());
    }
}
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–

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :