The java.util.GregorianCalendar.getTimeZone() method is an in-built method in Java which fetches the time zone and returns the TimeZone object associated with this calender.
public TimeZone getTimeZone()
Parameters: This method does not accept any parameter.
Return Values: This method returns a TimeZone object which denotes the time zone of this calendar.
Input : Mon Jul 23 19:45:33 UTC 2018 Output : Coordinated Universal Time Input : Wed Oct 23 20:02:52 UTC 2019 cal.setTimeZone(TimeZone.getTimeZone("CST")); Output : Central Standard Time
Below programs illustrate the java.util.GregorianCalendar.getTimeZone() function in Java:
Current Date and Time : Wed Jul 25 11:25:16 UTC 2018 Time Zone : Coordinated Universal Time
Program 2: In this program, we use setTimeZone() to change the current time zone and then fetch the new time zone using getTimeZone() method.
Current Date and Time : Wed Jul 25 11:25:22 UTC 2018 Time Zone : Central Standard Time
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.