.getTimeZone()
Published Sep 12, 2023
Contribute to Docs
The .getTimeZone()
method in the Calendar
class is used to return the current time-zone of a given calendar.
Syntax
time_zone = myCalendar.getTimeZone();
myCalendar
is aCalendar
class object for which the time zone is being retrieved.time_zone
is aTimeZone
class object returned from the.getTimeZone()
method.
Example
The following code demonstrates the use of the .getTimeZone()
method.
import java.util.*;public class Calendar_Demo {public static void main(String args[]){// Creating a calendar objectCalendar calndr = Calendar.getInstance();// Getting the time zone of calendarTimeZone time_zone = calndr.getTimeZone();// Displaying the current time zoneSystem.out.println("The current Time zone is: "+ time_zone.getDisplayName());}}
The above code will return an output similar to:
The current Time zone is: Coordinated Universal Time
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.