Java .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();
myCalendaris aCalendarclass object for which the time zone is being retrieved.time_zoneis aTimeZoneclass 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.
Learn Java on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
- Beginner Friendly.17 hours