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 :

N/A

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.

package com.javatutorialhq.java.examples;

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());
		cal.setTimeZone(TimeZone.getTimeZone("Pacific/Tahiti"));
		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 :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :