public class TimeZoneFormat
extends UFormat implements Freezable<TimeZoneFormat>, Serializable
| java.lang.Object | |||
| java.text.Format | |||
| android.icu.text.UFormat | |||
| android.icu.text.TimeZoneFormat | |||
TimeZoneFormat支持时区显示名称格式和解析。 TimeZoneFormat的实例作为SimpleDateFormat的子格式,但您也可以直接获取TimeZoneFormat的新实例以及格式化/解析时区显示名称。
ICU实现由UTS#35 Unicode Locale Data Markup Language (LDML)定义的时区显示名称。 TimeZoneNames表示时区显示名称数据模型,此类实现实际格式化和解析的算法。
也可以看看:
Nested classes |
|
|---|---|
枚举 |
TimeZoneFormat.GMTOffsetPatternType 偏移模式类型枚举。 |
枚举 |
TimeZoneFormat.ParseOption 解析选项枚举,用于指定可选的解析行为。 |
枚举 |
TimeZoneFormat.Style 格式/解析API在 |
枚举 |
TimeZoneFormat.TimeType 用于在 |
Protected constructors |
|
|---|---|
TimeZoneFormat(ULocale locale) 子类的保护构造函数。 |
|
公共方法(Public methods) |
|
|---|---|
TimeZoneFormat |
cloneAsThawed() 提供克隆操作。 |
StringBuffer |
format(Object obj, StringBuffer toAppendTo, FieldPosition pos) 格式化对象并将结果文本附加到给定的字符串缓冲区。 |
String |
format(TimeZoneFormat.Style style, TimeZone tz, long date, Output<TimeZoneFormat.TimeType> timeType) 返回样式给定日期的时区显示名称。 |
final String |
format(TimeZoneFormat.Style style, TimeZone tz, long date) 返回样式给定日期的时区显示名称。 |
final String |
formatOffsetISO8601Basic(int offset, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds) 返回给定偏移量的ISO 8601基本时区字符串。 |
final String |
formatOffsetISO8601Extended(int offset, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds) 返回给定偏移量的ISO 8601扩展时区字符串。 |
String |
formatOffsetLocalizedGMT(int offset) 返回给定偏移量的本地化GMT(UTC)偏移格式。 |
String |
formatOffsetShortLocalizedGMT(int offset) 返回给定偏移量的短局部化GMT(UTC)偏移格式。 |
AttributedCharacterIterator |
formatToCharacterIterator(Object obj) 格式化产生 |
TimeZoneFormat |
freeze() 冻结对象。 |
EnumSet<TimeZoneFormat.ParseOption> |
getDefaultParseOptions() 返回此 |
String |
getGMTOffsetDigits() 以升序方式返回包含从0到9的单个字符串中用于本地化GMT格式的十进制数字字符。 |
String |
getGMTOffsetPattern(TimeZoneFormat.GMTOffsetPatternType type) 返回用于本地化GMT格式的偏移模式。 |
String |
getGMTPattern() 返回本地化的格式GMT格式。 |
String |
getGMTZeroFormat() 返回格林尼治标准时间(UTC)本地化的GMT格式字符串(GMT偏移量为0)。 |
static TimeZoneFormat |
getInstance(Locale locale) 为给定的 |
static TimeZoneFormat |
getInstance(ULocale locale) 返回给定语言环境的冻结实例 |
TimeZoneNames |
getTimeZoneNames() 返回此实例使用的时区显示名称数据。 |
boolean |
isFrozen() 确定对象是否被冻结。 |
final TimeZone |
parse(String text) 返回给定文本的 |
final TimeZone |
parse(String text, ParsePosition pos) 根据给定的解析位置解析时区字符串,返回 |
TimeZone |
parse(TimeZoneFormat.Style style, String text, ParsePosition pos, Output<TimeZoneFormat.TimeType> timeType) 根据解析位置,样式和默认解析选项解析时区字符串,返回 |
TimeZone |
parse(TimeZoneFormat.Style style, String text, ParsePosition pos, EnumSet<TimeZoneFormat.ParseOption> options, Output<TimeZoneFormat.TimeType> timeType) 根据解析位置,样式和解析选项解析时区字符串,返回 |
Object |
parseObject(String source, ParsePosition pos) 分析字符串中的文本以生成对象。 |
final int |
parseOffsetISO8601(String text, ParsePosition pos) 返回给定ISO 8601基本或扩展时区字符串的GMT(UTC)(以毫秒为单位的偏移量)。 |
int |
parseOffsetLocalizedGMT(String text, ParsePosition pos) 对于给定的本地化GMT偏移格式字符串,返回GMT(UTC)以毫秒为单位的偏移量。 |
int |
parseOffsetShortLocalizedGMT(String text, ParsePosition pos) 返回GMT(UTC)的偏移量,以毫秒为单位给定短的局部GMT偏移格式字符串。 |
TimeZoneFormat |
setDefaultParseOptions(EnumSet<TimeZoneFormat.ParseOption> options) 设置默认分析选项。 |
TimeZoneFormat |
setGMTOffsetDigits(String digits) 设置用于本地化GMT格式的十进制数字字符。 |
TimeZoneFormat |
setGMTOffsetPattern(TimeZoneFormat.GMTOffsetPatternType type, String pattern) 设置给定偏移类型的偏移模式。 |
TimeZoneFormat |
setGMTPattern(String pattern) 设置本地化的GMT格式模式。 |
TimeZoneFormat |
setGMTZeroFormat(String gmtZeroFormat) 设置格林尼治标准时间(UTC)本地化的GMT格式字符串(GMT偏移量为0)。 |
TimeZoneFormat |
setTimeZoneNames(TimeZoneNames tznames) 将时区显示名称数据设置为此实例。 |
继承方法(Inherited methods) |
|
|---|---|
java.text.Format
|
|
java.lang.Object
|
|
android.icu.util.Freezable
|
|
TimeZoneFormat (ULocale locale)
子类的保护构造函数。
| 参数(Parameters) | |
|---|---|
locale |
ULocale: the locale |
TimeZoneFormat cloneAsThawed ()
提供克隆操作。 任何克隆都是最初解冻的。
| 返回(Returns) | |
|---|---|
TimeZoneFormat |
|
StringBuffer format (Object obj, StringBuffer toAppendTo, FieldPosition pos)
格式化对象并将结果文本附加到给定的字符串缓冲区。 如果参数pos标识该格式使用的字段,则其索引设置为遇到的第一个此类字段的开始和结尾。
| 参数(Parameters) | |
|---|---|
obj |
Object: The object to format |
toAppendTo |
StringBuffer: where the text is to be appended |
pos |
FieldPosition: A FieldPosition identifying a field in the formatted text |
| 返回(Returns) | |
|---|---|
StringBuffer |
the string buffer passed in as toAppendTo, with formatted text appended |
String format (TimeZoneFormat.Style style, TimeZone tz, long date, Output<TimeZoneFormat.TimeType> timeType)
返回样式给定日期的时区显示名称。 此方法需要一个额外的参数Output<TimeType> timeType除的参数列表format(Style, TimeZone, long) 。 该参数用于接收实际用于显示名称的时间类型(标准时间或夏令时或未知)。
| 参数(Parameters) | |
|---|---|
style |
TimeZoneFormat.Style: the style enum (e.g. GENERIC_LONG, LOCALIZED_GMT...) |
tz |
TimeZone: the time zone. |
date |
long: the date. |
timeType |
Output: the output argument for receiving the time type (standard/daylight/unknown) used for the display name, or specify null if the information is not necessary. |
| 返回(Returns) | |
|---|---|
String |
the display name of the time zone. |
String format (TimeZoneFormat.Style style, TimeZone tz, long date)
返回样式给定日期的时区显示名称。
注意 :样式可能会定义回退样式。 例如,当请求GENERIC_LONG ,但没有可用于GENERIC_LONG样式的显示名称数据时,实现可能使用GENERIC_LOCATION或LOCALIZED_GMT 。 有关详细信息,请参阅UTS#35 UNICODE LOCALE DATA MARKUP LANGUAGE(LDML) Appendix J: Time Zone Display Name 。
| 参数(Parameters) | |
|---|---|
style |
TimeZoneFormat.Style: the style enum (e.g. GENERIC_LONG, LOCALIZED_GMT...) |
tz |
TimeZone: the time zone. |
date |
long: the date. |
| 返回(Returns) | |
|---|---|
String |
the display name of the time zone. |
String formatOffsetISO8601Basic (int offset, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds)
返回给定偏移量的ISO 8601基本时区字符串。 例如,“-08”,“-0830”和“Z”
| 参数(Parameters) | |
|---|---|
offset |
int: the offset from GMT(UTC) in milliseconds. |
useUtcIndicator |
boolean: true if ISO 8601 UTC indicator "Z" is used when the offset is 0. |
isShort |
boolean: true if shortest form is used. |
ignoreSeconds |
boolean: true if non-zero offset seconds is appended. |
| 返回(Returns) | |
|---|---|
String |
the ISO 8601 basic format. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if the specified offset is out of supported range (-24 hours < offset < +24 hours). |
String formatOffsetISO8601Extended (int offset, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds)
返回给定偏移量的ISO 8601扩展时区字符串。 例如,“-08:00”,“-08:30”和“Z”
| 参数(Parameters) | |
|---|---|
offset |
int: the offset from GMT(UTC) in milliseconds. |
useUtcIndicator |
boolean: true if ISO 8601 UTC indicator "Z" is used when the offset is 0. |
isShort |
boolean: true if shortest form is used. |
ignoreSeconds |
boolean: true if non-zero offset seconds is appended. |
| 返回(Returns) | |
|---|---|
String |
the ISO 8601 extended format. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if the specified offset is out of supported range (-24 hours < offset < +24 hours). |
String formatOffsetLocalizedGMT (int offset)
返回给定偏移量的本地化GMT(UTC)偏移格式。 本地化的GMT偏移量由以下定义:
getGMTPattern()) getGMTOffsetPattern(GMTOffsetPatternType)) getGMTOffsetDigits()) getGMTZeroFormat()) | 参数(Parameters) | |
|---|---|
offset |
int: the offset from GMT(UTC) in milliseconds. |
| 返回(Returns) | |
|---|---|
String |
the localized GMT format string |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if the specified offset is out of supported range (-24 hours < offset < +24 hours). |
String formatOffsetShortLocalizedGMT (int offset)
返回给定偏移量的短局部化GMT(UTC)偏移格式。 短局部GMT时间偏移由以下定义:
getGMTPattern()) getGMTOffsetPattern(GMTOffsetPatternType)) getGMTOffsetDigits()) getGMTZeroFormat()) | 参数(Parameters) | |
|---|---|
offset |
int: the offset from GMT(UTC) in milliseconds. |
| 返回(Returns) | |
|---|---|
String |
the short localized GMT format string |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if the specified offset is out of supported range (-24 hours < offset < +24 hours). |
AttributedCharacterIterator formatToCharacterIterator (Object obj)
格式化产生AttributedCharacterIterator的对象。 您可以使用返回的AttributedCharacterIterator构建生成的字符串,以及确定有关生成的字符串的信息。
AttributedCharacterIterator的每个属性键都是类型Field 。 它是由每Format实现定义什么合法的值是在每个属性AttributedCharacterIterator ,但通常属性键也用作属性值。
默认实现创建一个没有属性的AttributedCharacterIterator 。 支持字段的子类应该覆盖该字段并创建具有有意义属性的AttributedCharacterIterator 。
| 参数(Parameters) | |
|---|---|
obj |
Object: The object to format |
| 返回(Returns) | |
|---|---|
AttributedCharacterIterator |
AttributedCharacterIterator describing the formatted value. |
TimeZoneFormat freeze ()
冻结对象。
| 返回(Returns) | |
|---|---|
TimeZoneFormat |
the object itself. |
EnumSet<TimeZoneFormat.ParseOption> getDefaultParseOptions ()
返回此 TimeZoneFormat实例使用的默认分析选项。
| 返回(Returns) | |
|---|---|
EnumSet<TimeZoneFormat.ParseOption> |
the default parse options. |
也可以看看:
String getGMTOffsetDigits ()
以升序方式返回包含从0到9的单个字符串中用于本地化GMT格式的十进制数字字符。
| 返回(Returns) | |
|---|---|
String |
the decimal digits for localized GMT format. |
也可以看看:
String getGMTOffsetPattern (TimeZoneFormat.GMTOffsetPatternType type)
返回用于本地化GMT格式的偏移模式。
| 参数(Parameters) | |
|---|---|
type |
TimeZoneFormat.GMTOffsetPatternType: the offset pattern enum |
| 返回(Returns) | |
|---|---|
String |
|
String getGMTPattern ()
返回本地化的格式GMT格式。
| 返回(Returns) | |
|---|---|
String |
the localized GMT format pattern. |
也可以看看:
String getGMTZeroFormat ()
返回格林尼治标准时间(UTC)本地化的GMT格式字符串(GMT偏移量为0)。
| 返回(Returns) | |
|---|---|
String |
the localized GMT string string for GMT(UTC) itself. |
也可以看看:
TimeZoneFormat getInstance (Locale locale)
为给定的 Locale返回一个 TimeZoneFormat的冻结实例。
注意 :此方法返回的实例被冻结。 如果您想定制TimeZoneFormat,则必须先使用cloneAsThawed()才能获得解冻后的副本。
| 参数(Parameters) | |
|---|---|
locale |
Locale: the Locale. |
| 返回(Returns) | |
|---|---|
TimeZoneFormat |
a frozen instance of TimeZoneFormat for the given locale. |
TimeZoneFormat getInstance (ULocale locale)
返回给定语言环境的冻结实例 TimeZoneFormat 。
注意 :此方法返回的实例被冻结。 如果您想自定义TimeZoneFormat,则必须先使用cloneAsThawed()才能获得解冻后的副本。
| 参数(Parameters) | |
|---|---|
locale |
ULocale: the locale. |
| 返回(Returns) | |
|---|---|
TimeZoneFormat |
a frozen instance of TimeZoneFormat for the given locale. |
TimeZoneNames getTimeZoneNames ()
返回此实例使用的时区显示名称数据。
| 返回(Returns) | |
|---|---|
TimeZoneNames |
the time zone display name data. |
TimeZone parse (String text)
给定文本返回 TimeZone 。
注意 :此方法的行为等同于 parse(String, ParsePosition) 。
| 参数(Parameters) | |
|---|---|
text |
String: the time zone string |
| 返回(Returns) | |
|---|---|
TimeZone |
A TimeZone. |
| 抛出异常(Throws) | |
|---|---|
ParseException |
when the input could not be parsed as a time zone string. |
也可以看看:
TimeZone parse (String text, ParsePosition pos)
根据给定的解析位置解析时区字符串,返回 TimeZone 。
注意 :此方法相当于 parse(Style.GENERIC_LOCATION, text, pos, EnumSet.of(ParseOption.ALL_STYLES), timeType) 。
| 参数(Parameters) | |
|---|---|
text |
String: the text contains a time zone string at the position. |
pos |
ParsePosition: the position. |
| 返回(Returns) | |
|---|---|
TimeZone |
A TimeZone, or null if the input could not be parsed. |
TimeZone parse (TimeZoneFormat.Style style, String text, ParsePosition pos, Output<TimeZoneFormat.TimeType> timeType)
根据解析位置,样式和默认解析选项解析时区字符串,返回 TimeZone 。
注意 :此方法相当于 parse(style, text, pos, null, timeType) 。
| 参数(Parameters) | |
|---|---|
style |
TimeZoneFormat.Style: the format style |
text |
String: the text contains a time zone string at the position. |
pos |
ParsePosition: the position. |
timeType |
Output: The output argument for receiving the time type (standard/daylight/unknown), or specify null if the information is not necessary. |
| 返回(Returns) | |
|---|---|
TimeZone |
A TimeZone, or null if the input could not be parsed. |
TimeZone parse (TimeZoneFormat.Style style, String text, ParsePosition pos, EnumSet<TimeZoneFormat.ParseOption> options, Output<TimeZoneFormat.TimeType> timeType)
根据解析位置,样式和解析选项解析时区字符串,返回 TimeZone 。
| 参数(Parameters) | |
|---|---|
style |
TimeZoneFormat.Style: the format style. |
text |
String: the text contains a time zone string at the position. |
pos |
ParsePosition: the position. |
options |
EnumSet: the parse options. |
timeType |
Output: The output argument for receiving the time type (standard/daylight/unknown), or specify null if the information is not necessary. |
| 返回(Returns) | |
|---|---|
TimeZone |
A TimeZone, or null if the input could not be parsed. |
Object parseObject (String source, ParsePosition pos)
分析字符串中的文本以生成对象。
该方法试图解析从pos给出的索引开始的文本。 如果解析成功,则在使用最后一个字符(解析不一定使用到字符串末尾的所有字符)之后,将索引pos更新为索引,并返回解析对象。 已更新的pos可用于指示下一次调用此方法的起点。 如果发生错误,则pos的索引不会更改,将错误索引pos设置为发生错误的字符的索引,并返回null。
| 参数(Parameters) | |
|---|---|
source |
String: A String, part of which should be parsed. |
pos |
ParsePosition: A ParsePosition object with index and error index information as described above. |
| 返回(Returns) | |
|---|---|
Object |
An Object parsed from the string. In case of error, returns null. |
int parseOffsetISO8601 (String text, ParsePosition pos)
返回给定ISO 8601基本或扩展时区字符串的GMT(UTC)(以毫秒为单位的偏移量)。 当给定字符串不是ISO 8601时区字符串时,此方法将当前位置设置为错误索引ParsePosition pos并返回0。
| 参数(Parameters) | |
|---|---|
text |
String: the text contains ISO 8601 style time zone string (e.g. "-08", "-0800", "-08:00", and "Z") at the position. |
pos |
ParsePosition: the position. |
| 返回(Returns) | |
|---|---|
int |
the offset from GMT(UTC) in milliseconds for the given ISO 8601 style time zone string. |
int parseOffsetLocalizedGMT (String text, ParsePosition pos)
对于给定的本地化GMT偏移格式字符串,返回GMT(UTC)以毫秒为单位的偏移量。 当给定的字符串不能被解析时,该方法将当前位置设置为错误索引ParsePosition pos并返回0。
| 参数(Parameters) | |
|---|---|
text |
String: the text contains a localized GMT offset string at the position. |
pos |
ParsePosition: the position. |
| 返回(Returns) | |
|---|---|
int |
the offset from GMT(UTC) in milliseconds for the given localized GMT offset format string. |
int parseOffsetShortLocalizedGMT (String text, ParsePosition pos)
返回GMT(UTC)的偏移量,以毫秒为单位给定短的局部GMT偏移格式字符串。 当给定的字符串不能被解析时,这个方法将当前位置设置为错误索引ParsePosition pos并返回0。
| 参数(Parameters) | |
|---|---|
text |
String: the text contains a short localized GMT offset string at the position. |
pos |
ParsePosition: the position. |
| 返回(Returns) | |
|---|---|
int |
the offset from GMT(UTC) in milliseconds for the given short localized GMT offset format string. |
TimeZoneFormat setDefaultParseOptions (EnumSet<TimeZoneFormat.ParseOption> options)
设置默认分析选项。
注意:默认情况下,实例 TimeZoneFormat由{#LINK创建 getInstance(ULocale)有没有设定解析选项。
| 参数(Parameters) | |
|---|---|
options |
EnumSet: the default parse options. |
| 返回(Returns) | |
|---|---|
TimeZoneFormat |
this object. |
也可以看看:
TimeZoneFormat setGMTOffsetDigits (String digits)
设置用于本地化GMT格式的十进制数字字符。
| 参数(Parameters) | |
|---|---|
digits |
String: a string contains the decimal digit characters from 0 to 9 n the ascending order. |
| 返回(Returns) | |
|---|---|
TimeZoneFormat |
this object. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
when the string did not contain ten characters. |
UnsupportedOperationException |
when this object is frozen. |
也可以看看:
TimeZoneFormat setGMTOffsetPattern (TimeZoneFormat.GMTOffsetPatternType type, String pattern)
设置给定偏移类型的偏移模式。
| 参数(Parameters) | |
|---|---|
type |
TimeZoneFormat.GMTOffsetPatternType: the offset pattern. |
pattern |
String: the pattern string. |
| 返回(Returns) | |
|---|---|
TimeZoneFormat |
this object. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
when the pattern string does not have required time field letters. |
UnsupportedOperationException |
when this object is frozen. |
TimeZoneFormat setGMTPattern (String pattern)
设置本地化的GMT格式模式。 该模式必须包含单个参数{0},例如“GMT {0}”。
| 参数(Parameters) | |
|---|---|
pattern |
String: the localized GMT format pattern string |
| 返回(Returns) | |
|---|---|
TimeZoneFormat |
this object. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
when the pattern string does not contain "{0}" |
UnsupportedOperationException |
when this object is frozen. |
也可以看看:
TimeZoneFormat setGMTZeroFormat (String gmtZeroFormat)
设置格林尼治标准时间(UTC)本地化的GMT格式字符串(GMT偏移量为0)。
| 参数(Parameters) | |
|---|---|
gmtZeroFormat |
String: the localized GMT format string for GMT(UTC). |
| 返回(Returns) | |
|---|---|
TimeZoneFormat |
this object. |
| 抛出异常(Throws) | |
|---|---|
UnsupportedOperationException |
when this object is frozen. |
也可以看看:
TimeZoneFormat setTimeZoneNames (TimeZoneNames tznames)
将时区显示名称数据设置为此实例。
| 参数(Parameters) | |
|---|---|
tznames |
TimeZoneNames: the time zone display name data. |
| 返回(Returns) | |
|---|---|
TimeZoneFormat |
this object. |
| 抛出异常(Throws) | |
|---|---|
UnsupportedOperationException |
when this object is frozen. |
也可以看看: