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:GMTSign Hours:MinutesGMTSign Hours MinutesGMTSign 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:GMTSign 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.