java.util.Calendar getTimeZone()

Description :

This java tutorial shows how to use the getTimeZone() method of Calendar class of java.util package. This method gets the time zone.

Method Syntax :

public TimeZone getTimeZone()

Parameter Input :

 

DataType Parameter Description
N/A N/A N/A

 

Method Returns :

This method returns the time zone object associated with this calendar.

Compatibility Version :

Requires Java 1.1 and up

Exception :

N/A

Java Code Example :

This java example source code demonstrates the use of getTimeZone() method of Calendar class. Basically we just set the timezone and then prints the current timezone.

package com.javatutorialhq.java.examples;

import java.util.Calendar;
import java.util.TimeZone;

/*
 * This example source code demonstrates the use of  
 * getTimeZone() method of Calendar class
 */

public class CalendarGetTimeZoneExample {

	public static void main(String[] args) {

		Calendar cal = Calendar.getInstance();
		System.out.println("Current TimeZone:"
				+ cal.getTimeZone().getDisplayName());
		cal.setTimeZone(TimeZone.getTimeZone("GMT"));
		System.out.println("New Time Zone:"
				+ cal.getTimeZone().getDisplayName());
		

	}
}

Sample Output :

Running the getTimeZone() method example source code of Calendar class will give you the following output:

Current TimeZone:China Standard Time
New Time Zone:Greenwich Mean Time

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :