Open In App

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 parameters.
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–


Article Tags :