public abstract class TimeZone extends Object implements Serializable, Cloneable
TimeZone
代表一个时区偏移量,指出夏令时。
通常,你会得到一个TimeZone
使用getDefault
创造一个TimeZone
基于时区,程序运行。例如,一个程序运行在日本,getDefault
创建一个基于日本标准时间TimeZone
对象。
你也可以使用getTimeZone
随着时区ID,例如得到一个TimeZone
,为美国太平洋时区的时区ID是“美国/ los_angeles”。所以,你可以得到一个美国太平洋时间TimeZone
对象:
可以使用TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
getAvailableIDs
方法遍历所有支持时区ID。然后你可以选择一个支持的ID得到一个
TimeZone
。如果时间带你想要的不是一个IDS表示支持,然后带身份证可以生成特定的时区自定义时间。一个自定义时区ID的语法是:
小时必须在0到23之间,分钟必须介于00到59。例如,“北京时间10”和“0010”,平均十小时和十分钟,比北京时间分别为。CustomID:GMT
Sign Hours:
MinutesGMT
Sign Hours MinutesGMT
Sign Hours Sign: one of+ -
Hours: Digit Digit Digit Minutes: Digit Digit Digit: one of0 1 2 3 4 5 6 7 8 9
格式是现场独立的数字必须从Unicode标准的基本拉丁语块。没有日光节约时间的过渡计划可以指定一个自定义时区ID。如果指定的字符串不符合语法,"GMT"
使用。
创建一个TimeZone
时,指定的自定义时区ID是在下面的语法规范:
例如,时区。gettimezone(“gmt-8”)。getid()返回“GMT-08:00”。在JDK 1.1的兼容性NormalizedCustomID:GMT
Sign TwoDigitHours:
Minutes Sign: one of+ -
TwoDigitHours: Digit Digit Minutes: Digit Digit Digit: one of0 1 2 3 4 5 6 7 8 9
Calendar
,
GregorianCalendar
,
SimpleTimeZone
,
Serialized Form
Modifier and Type | Field and Description |
---|---|
static int |
LONG
风格
getDisplayName() 指示一个很长的名字说明符,如“太平洋标准时间。”
|
static int |
SHORT
风格
getDisplayName() 指示短名称说明符,如“科普”。
|
Constructor and Description |
---|
TimeZone()
唯一的构造函数。
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
复制这
TimeZone 。
|
static String[] |
getAvailableIDs()
获取支持的所有可用的标识。
|
static String[] |
getAvailableIDs(int rawOffset)
根据给定的时区偏移以毫秒为单位获取可用的入侵检测系统。
|
static TimeZone |
getDefault()
获取java虚拟机默认的
TimeZone 。
|
String |
getDisplayName()
返回本
TimeZone 适合表现在默认区域设置用户长时间的名字。
|
String |
getDisplayName(boolean daylight, int style)
返回一个指定名称的
style 这
TimeZone 适合表现在默认区域设置的用户。
|
String |
getDisplayName(boolean daylight, int style, Locale locale)
返回一个指定名称的
style 这
TimeZone 适合呈现在用户指定的
locale 。
|
String |
getDisplayName(Locale locale)
返回本
TimeZone 适合呈现在指定的
locale 用户长时间的名字。
|
int |
getDSTSavings()
返回添加到本地标准时间的时间,以获得本地的墙上时钟时间。
|
String |
getID()
获取此时区的标识。
|
abstract int |
getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)
获取当前日期的时区偏移量,以进行日光节约的情况下进行修改。
|
int |
getOffset(long date)
返回该时区的UTC偏移量在指定的日期。
|
abstract int |
getRawOffset()
返回的时间在毫秒数量增加时会在这个时区的标准时间。
|
static TimeZone |
getTimeZone(String ID)
获取给定ID的
TimeZone
|
static TimeZone |
getTimeZone(ZoneId zoneId)
获取给定
zoneId 的
TimeZone 。
|
boolean |
hasSameRules(TimeZone other)
如果此区域具有相同的规则和偏移量作为另一个区域,则返回真。
|
abstract boolean |
inDaylightTime(Date date)
如果给定的
date 查询在这个时区夏令时。
|
boolean |
observesDaylightTime()
返回
true 如果这
TimeZone 目前在日光节约时间,或者如果一个标准时间夏令时转变发生在未来的任何时间。
|
static void |
setDefault(TimeZone zone)
集
TimeZone 是由
getDefault 方法返回。
|
void |
setID(String ID)
设置时区标识。
|
abstract void |
setRawOffset(int offsetMillis)
设置偏移的基本时间区
|
ZoneId |
toZoneId()
将这一
ZoneId
TimeZone 对象。
|
abstract boolean |
useDaylightTime()
如果这
TimeZone 查询使用日光节约时间。
|
public static final int SHORT
getDisplayName()
指示短名称说明符,如“科普”。
LONG
,
Constant Field Values
public static final int LONG
getDisplayName()
指示一个很长的名字说明符,如“太平洋标准时间。”
SHORT
,
Constant Field Values
public abstract int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)
此方法返回一个历史正确的偏移量,如果一个潜在的TimeZone
实现的子类支持历史日光节约时间进度和GMT偏移的变化。
era
-给定日期的时代。
year
在给定日期的年份。
month
在给定日期的月。月是0。例如,一月的0。
day
在给定日期月日。
dayOfWeek
给定日期的星期。
milliseconds
标准日毫秒。
Calendar.ZONE_OFFSET
,
Calendar.DST_OFFSET
public int getOffset(long date)
此方法返回一个历史正确的偏移值,如果一个潜在的时区实现的子类支持历史日光节约时间进度和GMT偏移的变化。
date
表示的毫秒自1970年1月1日00:00:00 GMT日期
Calendar.ZONE_OFFSET
,
Calendar.DST_OFFSET
public abstract void setRawOffset(int offsetMillis)
如果一个潜在的TimeZone
实现的子类支持历史GMT偏移变化,指定的GMT偏移设置为新的GMT偏移和已知新GMT偏移值的差异是用来调整所有历史GMT偏移值。
offsetMillis
-给定的基本的时区偏移GMT。
public abstract int getRawOffset()
如果一个潜在的TimeZone
实现的子类支持历史GMT偏移的变化,该方法返回当前日期的原始偏移值。在火奴鲁鲁,例如,其原始偏移从gmt-10:30到gmt-10:00 1947,该方法总是返回36000000毫秒(即10小时)。
Calendar.ZONE_OFFSET
public String getID()
public void setID(String ID)
ID
-新时区的ID。
public final String getDisplayName()
TimeZone
适合表现在默认区域设置用户长时间的名字。
此方法相当于:
getDisplayName(false,LONG
, Locale.getDefault(Locale.Category.DISPLAY
))
getDisplayName(boolean, int, Locale)
,
Locale.getDefault(Locale.Category)
,
Locale.Category
public final String getDisplayName(Locale locale)
locale
在现场提供的显示名称。
null
locale
NullPointerException
。
getDisplayName(boolean, int, Locale)
public final String getDisplayName(boolean daylight, int style)
style
这
TimeZone
适合表现在默认区域设置的用户。如果指定的
daylight
是
true
,夏时制的名字返回(即使这
TimeZone
不遵守夏令时间)。否则,返回一个标准的时间名称。
此方法相当于:
getDisplayName(daylight, style, Locale.getDefault(Locale.Category.DISPLAY
))
daylight
-
true
指定日光节约时间的名字,或
false
指定标准时间的名字
style
-
LONG
或
SHORT
IllegalArgumentException
-如果
style
无效。
getDisplayName(boolean, int, Locale)
,
Locale.getDefault(Locale.Category)
,
Locale.Category
,
DateFormatSymbols.getZoneStrings()
public String getDisplayName(boolean daylight, int style, Locale locale)
style
这
TimeZone
适合呈现在用户指定的
locale
。如果指定的
daylight
是
true
,夏时制的名字返回(即使这
TimeZone
不遵守夏令时间)。否则,返回一个标准的时间名称。
当寻找一个时区名称,来自指定的default Locale
search path of ResourceBundle
locale
使用。(执行。没有fallback Locale
搜索)如果一个时区名称在任何Locale
的搜索路径,包括Locale.ROOT
,找到了,叫回来。否则,在normalized custom ID format字符串返回。
daylight
-
true
指定日光节约时间的名字,或
false
指定标准时间的名字
style
-
LONG
或
SHORT
locale
在现场提供的显示名称。
IllegalArgumentException
-如果
style
无效。
null
locale
NullPointerException
。
DateFormatSymbols.getZoneStrings()
public int getDSTSavings()
默认实现将返回3600000毫秒(即一小时)如果调用useDaylightTime()
返回true
。否则,返回0(零)。
如果一个潜在的TimeZone
实现的子类支持的历史和未来的日光节约时间的变化,该方法返回的最后为人所知的日光节约时间的规律,可以预测未来节省时间。
如果在任何给定的时间戳是需要节约时间,构建一个Calendar
这个TimeZone
和时间戳,并称Calendar.get
(
Calendar.DST_OFFSET
)
。
inDaylightTime(Date)
,
getOffset(long)
,
getOffset(int,int,int,int,int,int)
,
Calendar.ZONE_OFFSET
public abstract boolean useDaylightTime()
TimeZone
查询使用日光节约时间。
如果一个潜在的TimeZone
实现的子类支持的历史和未来的日光节约时间的变化,这种方法是指最后已知日光节约时间的规则,可以是一个未来的预测不可能像电流一样的规则。考虑调用observesDaylightTime()
如果当前的规则也应考虑。
true
TimeZone
使用日光节约时间,
false
,否则。
inDaylightTime(Date)
,
Calendar.DST_OFFSET
public boolean observesDaylightTime()
true
如果这
TimeZone
目前在日光节约时间,或者如果一个标准时间夏令时转变发生在未来的任何时间。
默认的实现返回true
如果useDaylightTime()
或inDaylightTime(new Date())
返回true
。
true
TimeZone
目前在日光节约时间,或者如果一个标准时间夏令时转变发生在未来的任何时间;
false
否则。
useDaylightTime()
,
inDaylightTime(Date)
,
Calendar.DST_OFFSET
public abstract boolean inDaylightTime(Date date)
date
查询在这个时区夏令时。
date
-给定的日期。
true
如果给定的日期是在日光节约时间,
false
,否则。
public static TimeZone getTimeZone(String ID)
TimeZone
ID
-一
TimeZone
ID,或者一个缩写如“科普”,一个完整的名称如“美国/ los_angeles”,或一个自定义的ID如“gmt-8:00”。注意缩略语的支持是JDK 1.1。x的兼容性和完整的名称应使用。
TimeZone
,或格林威治区如果我不能理解。
public static TimeZone getTimeZone(ZoneId zoneId)
zoneId
的
TimeZone
。
zoneId
-
ZoneId
从中得到的时间带身份证
TimeZone
,或格林威治区如果我不能理解。
null
zoneId
NullPointerException
public ZoneId toZoneId()
ZoneId
TimeZone
对象。
ZoneId
代表同一时区的这
TimeZone
public static String[] getAvailableIDs(int rawOffset)
rawOffset
-给定的时区偏移毫秒。
getRawOffset()
public static String[] getAvailableIDs()
public static TimeZone getDefault()
TimeZone
。如果缓存的默认
TimeZone
可用,其克隆返回。否则,该方法需要以下步骤来确定默认时区。
user.timezone
属性值作为默认时区ID。GMT
作为最后的手段,如果给定的或检测到的时区ID是未知的。默认TimeZone
创建ID时,其克隆返回。的user.timezone
属性值设置为身份回国。
TimeZone
setDefault(TimeZone)
public static void setDefault(TimeZone zone)
TimeZone
是由
getDefault
方法返回。
zone
缓存。如果
zone
为空,默认
TimeZone
清除缓存。该方法不改变的
user.timezone
属性的值。
zone
-新的默认
TimeZone
,或空
SecurityException
-如果安全经理的
checkPermission
否认
PropertyPermission("user.timezone", "write")
getDefault()
,
PropertyPermission
public boolean hasSameRules(TimeZone other)
other
要与
TimeZone
对象
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.