GregorianCalendar class setTimeZone(TimeZone zone) method example
Sets the time zone with the given time zone value.
GregorianCalendarclass setTimeZone(TimeZone zone) method example. This example shows you how to use setTimeZone(TimeZone zone) method.This method Sets the time zone with the given time zone value.
Here is the code:-
/**
* @Program that Sets the time zone with the given time zone value.
* setTimeZone.java
* Author:-RoseIndia Team
* Date:-27-May-2008
*/
import java.util.*;
public class setTimeZone {
public static void main(String[] args) {
GregorianCalendar g = new GregorianCalendar();
//Displays the date of the Calendar
System.out.println("Current TimeZone of the Calendar is: " + g.getTimeZone().getID());
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
//Sets the time zone with the given time zone value.
g.setTimeZone(tz);
System.out.println("Current TimeZone of the Calendar is: " + g.getTimeZone().getID());
}
} |
Output of the program:-
Current TimeZone of the Calendar is: Asia/Calcutta
Current TimeZone of the Calendar is: America/Los_Angeles |
|