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:
// 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()); } } |
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()); } } |
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–
Recommended Posts:
- TimeZone getTimeZone() Method in Java with Examples
- DateFormat getTimeZone() Method in Java with Examples
- Calendar get() method in Java with Examples
- Calendar add() Method in Java with Examples
- Calendar set() Method in Java with Examples
- GregorianCalendar getTimeZone() Method in Java
- Calendar isLenient() Method in Java with Examples
- Calendar getTimeInMillis() Method in Java with Examples
- Calendar getMinimum() Method in Java with Examples
- Calendar getGreatestMinimum() Method in Java with Examples
- Calendar getInstance() Method in Java with Examples
- Calendar getLeastMaximum() method in Java with Examples
- Calendar getMaximum() method in Java with Examples
- Calendar getMinimalDaysInFirstWeek() Method in Java with Examples
- Calendar hashCode() Method in Java with Examples
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.



