settimezone
日历类setTimeZone()方法 (Calendar Class setTimeZone() method)
setTimeZone() method is available in java.util package.
setTimeZone()方法在java.util包中可用。
setTimeZone() method is used to sets the current time from the given parameter (time_in_ms) of this Calendar.
setTimeZone()方法用于根据此Calendar的给定参数(time_in_ms)设置当前时间。
setTimeZone() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
setTimeZone()方法是一种非静态方法,可通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
setTimeZone() method does not throw an exception at the time of set time in UTC milliseconds.
setTimeZone()方法在设置时间(以UTC毫秒为单位)时不会引发异常。
Syntax:
句法:
public void setTimeZone(TimeZone tz);
Parameter(s):
参数:
TimeZone tz – represents the specified time zone.
TimeZone tz –表示指定的时区。
Return value:
返回值:
The return type of this method is void, it returns nothing.
此方法的返回类型为void ,不返回任何内容。
Example:
例:
// Java Program to demonstrate the example of
// void setTimeZone(TimeZone tz) method of
// Calendar
import java.util.*;
public class SetTimeZone {
public static void main(String args[]) {
// Instantiating a Calendar object
Calendar ca = Calendar.getInstance();
TimeZone time_zo = TimeZone.getTimeZone("EST");
// By using setTimeZone(TimeZone) method is to
// set the time zone of the current
// Calendar
ca.setTimeZone(time_zo);
// Display Current Calendar TimeZone
System.out.println("ca.getTimeZone().getDisplayName(): " + ca.getTimeZone().getDisplayName());
}
}
Output
输出量
ca.getTimeZone().getDisplayName(): Eastern Standard Time
翻译自: https://www.includehelp.com/java/calendar-settimezone-method-with-example.aspx
settimezone