java.util.Calendar setTimeZone(TimeZone value)

Description :

This java tutorial shows how to use the setTimeZone(TimeZone value) method of Calendar class of java.util package. This method sets the time zone with the given time zone value.

Method Syntax :

public void setTimeZone(TimeZone value)

Parameter Input :


DataType Parameter Description
TimeZone value the given timezone


Method Returns :

This method returns void.

Compatibility Version :

Requires Java 1.1 and up

Exception :


Java Code Example :

This java example source code demonstrates the use of setTimeZone(TimeZone value)  method of Calendar class. Basically we just set the timezone and then prints the time.


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

 * This example source code demonstrates the use of  
 * setTimeZone(TimeZone value) method of Calendar class

public class CalendarSetTimeZoneExample {

	public static void main(String[] args) {

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


Sample Output :

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

Current TimeZone:China Standard Time
New TimeZone:Tahiti Time

Exception Scenario :


Similar Method :

  • N/A

Suggested Reading List :

References :