java.util.Calendar.setTime(TimeZone)%uA0方法用给定的时区值设置时区。
声明
以下是java.util.Calendar.setTime()方法的声明
public void setTimeZone(TimeZone value)
参数
-
value%uA0-- 给定的时区
返回值
此方法不返回任何值。
异常
-
NA
例子
下面的示例演示java.util.calendar.setTimeZone()方法的用法。
package com.yiibai import java.util.* public class CalendarDemo { public static void main(String[] args) { // create a calendar Calendar cal = Calendar.getInstance() // print current time zone String name=cal.getTimeZone().getDisplayName() System.out.println("Current Time Zone:" + name ) TimeZone tz = TimeZone.getTimeZone("GMT") // set the time zone with the given time zone value // and print it cal.setTimeZone(tz) System.out.println(cal.getTimeZone().getDisplayName()) } }
让我们来编译和运行上面的程序,这将产生以下结果:
Current Time Zone:Eastern European Time Greenwich Mean Time