java.util.GregorianCalendar.setTimeZone(TimeZone zone)%uA0方法用给定的时区值用来设置时区。
声明
以下是java.util.GregorianCalendar.setTimeZone()方法的声明
public void setTimeZone(TimeZone zone)
参数
-
zone%uA0-- 给定的时区。
返回值
此方法不返回任何值。
异常
-
NA
例子
下面的示例演示java.util.GregorianCalendar.setTimeZone()方法的用法。
package com.yiibai import java.util.* public class GregorianCalendarDemo { public static void main(String[] args) { // create a new calendar GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance() // print the current date and time System.out.println("" + cal.getTime()) // set to another time zone cal.setTimeZone(TimeZone.getTimeZone("GMT")) System.out.println("New Time Zone:" + cal.getTimeZone().getDisplayName()) } }
让我们来编译和运行上面的程序,这将产生以下结果:
Fri May 18 13:48:30 EEST 2012 New Time Zone:Greenwich Mean Time