Top Description Inners Fields Constructors Methods
com.ibm.icu.text

public Class TimeZoneFormat

extends UFormat
implements Freezable<TimeZoneFormat>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.ibm.icu.util.Freezable, java.lang.Cloneable
Imports
java.io.IOException, .InvalidObjectException, .ObjectInputStream, .ObjectOutputStream, .ObjectStreamField, .Serializable, java.text.AttributedCharacterIterator, .AttributedString, .FieldPosition, .ParseException, .ParsePosition, java.util.ArrayList, .BitSet, .Collection, .Date, .EnumSet, .Iterator, .List, .Locale, .MissingResourceException, .Set, com.ibm.icu.impl.ICUData, .ICUResourceBundle, .PatternProps, .SoftCache, .TZDBTimeZoneNames, .TextTrieMap, .TimeZoneGenericNames, .TimeZoneGenericNames.GenericMatchInfo, .TimeZoneGenericNames.GenericNameType, .TimeZoneNamesImpl, .ZoneMeta, com.ibm.icu.lang.UCharacter, com.ibm.icu.text.TimeZoneNames.MatchInfo, .TimeZoneNames.NameType, com.ibm.icu.util.Calendar, .Freezable, .Output, .TimeZone, .TimeZone.SystemTimeZoneType, .ULocale

TimeZoneFormat supports time zone display name formatting and parsing. An instance of TimeZoneFormat works as a subformatter of SimpleDateFormat, but you can also directly get a new instance of TimeZoneFormat and formatting/parsing time zone display names.

ICU implements the time zone display names defined by UTS#35 Unicode Locale Data Markup Language (LDML). TimeZoneNames represents the time zone display name data model and this class implements the algorithm for actual formatting and parsing.

ICU Status
Stable since ICU 49.
See Also
SimpleDateFormat, TimeZoneNames

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
TimeZoneFormat.GMTOffsetField

Used for representing localized GMT time fields in the parsed pattern object.

public static enum
TimeZoneFormat.GMTOffsetPatternType

Offset pattern type enum.

private static enum
TimeZoneFormat.OffsetFields

Numeric offset field combinations

public static enum
TimeZoneFormat.ParseOption

Parse option enum, used for specifying optional parse behavior.

public static enum
TimeZoneFormat.Style

Time zone display format style enum used by format/parse APIs in TimeZoneFormat.

public static enum
TimeZoneFormat.TimeType

Time type enum used for receiving time type (standard time, daylight time or unknown) in TimeZoneFormat APIs.

private static class
TimeZoneFormat.TimeZoneFormatCache

Implements TimeZoneFormat object cache

Field Summary

Modifier and TypeField and Description
private transient boolean
private transient volatile boolean
private String[]
private transient Object[][]
private String[]
private String
private transient String
private transient String
private String
private transient volatile TimeZoneGenericNames
private ULocale
private boolean
private boolean
private transient String
private transient volatile TimeZoneNames
private static TimeZoneFormat.TimeZoneFormatCache
private TimeZoneNames
private static final EnumSet<TimeZoneGenericNames.GenericNameType>
private static final EnumSet<TimeZoneNames.NameType>
private static final String[]
private static final String
private static final String[]
private static final char
private static final String
private static final String
private static final String
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final TimeZoneFormat.GMTOffsetPatternType[]
private static final ObjectStreamField[]
private static final long
private static volatile TextTrieMap<String>
private static final String
private static final String
private static final int
private static final String
private static final String
private static volatile TextTrieMap<String>

Constructor Summary

AccessConstructor and Description
protected
TimeZoneFormat(ULocale
the locale
locale
)

The protected constructor for subclassing.

Method Summary

Modifier and TypeMethod and Description
private void
appendOffsetDigits(StringBuilder
the target buffer
buf
,
int
the integer number
n
,
int
the minimum digits width
minDigits
)

Appends localized digits to the buffer.

private void
public TimeZoneFormat
cloneAsThawed()

Implements com.ibm.icu.util.Freezable.cloneAsThawed.

Provides for the clone operation.
private static String

Returns:

the offset pattern including hours, minutes and seconds fields
expandOffsetPattern
(String
the offset pattern including hours and minutes fields
offsetHM
)

Appends seconds field to the offset pattern with hour/minute

public final String

Returns:

the display name of the time zone.
format
(TimeZoneFormat.Style
the style enum (e.g. GENERIC_LONG, LOCALIZED_GMT...)
style
,
TimeZone
the time zone.
tz
,
long
the date.
date
)

Returns the display name of the time zone at the given date for the style.

public String

Returns:

the display name of the time zone.
format
(TimeZoneFormat.Style
the style enum (e.g. GENERIC_LONG, LOCALIZED_GMT...)
style
,
TimeZone
the time zone.
tz
,
long
the date.
date
,
Output<TimeZoneFormat.TimeType>
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.
timeType
)

Returns the display name of the time zone at the given date for the style.

public StringBuffer
format(Object
The object to format
obj
,
StringBuffer
where the text is to be appended
toAppendTo
,
FieldPosition
A FieldPosition identifying a field in the formatted text
pos
)

Implements abstract java.text.Format.format.

Formats an object and appends the resulting text to a given string buffer.
private String

Returns:

the time zone's exemplar location name.
formatExemplarLocation
(TimeZone
the time zone
tz
)

Private method returning the time zone's exemplar location string.

private String
formatOffsetISO8601(int offset, boolean isBasic, boolean useUtcIndicator, boolean isShort, boolean ignoreSeconds)

public final String

Returns:

the ISO 8601 basic format.
formatOffsetISO8601Basic
(int
the offset from GMT(UTC) in milliseconds.
offset
,
boolean
true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
useUtcIndicator
,
boolean
true if shortest form is used.
isShort
,
boolean
true if non-zero offset seconds is appended.
ignoreSeconds
)

Returns the ISO 8601 basic time zone string for the given offset.

public final String

Returns:

the ISO 8601 extended format.
formatOffsetISO8601Extended
(int
the offset from GMT(UTC) in milliseconds.
offset
,
boolean
true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
useUtcIndicator
,
boolean
true if shortest form is used.
isShort
,
boolean
true if non-zero offset seconds is appended.
ignoreSeconds
)

Returns the ISO 8601 extended time zone string for the given offset.

public String

Returns:

the localized GMT format string
formatOffsetLocalizedGMT
(int
the offset from GMT(UTC) in milliseconds.
offset
)

Returns the localized GMT(UTC) offset format for the given offset.

private String

Returns:

the localized GMT string
formatOffsetLocalizedGMT
(int
the zone's UTC offset
offset
,
boolean
true if the short localized GMT format is desired
isShort
)

Private method used for localized GMT formatting.

public String

Returns:

the short localized GMT format string
formatOffsetShortLocalizedGMT
(int
the offset from GMT(UTC) in milliseconds.
offset
)

Returns the short localized GMT(UTC) offset format for the given offset.

private String

Returns:

the time zone's specific format name string
formatSpecific
(TimeZone
the time zone
tz
,
TimeZoneNames.NameType
the name type used for standard time
stdType
,
TimeZoneNames.NameType
the name type used for daylight time
dstType
,
long
the date
date
,
Output<TimeZoneFormat.TimeType>
when null, actual time type is set
timeType
)

Private method returning the time zone's specific format string.

public AttributedCharacterIterator
formatToCharacterIterator(Object
The object to format
obj
)

Overrides java.text.Format.formatToCharacterIterator.

Formats an Object producing an AttributedCharacterIterator.
public TimeZoneFormat
freeze()

Implements com.ibm.icu.util.Freezable.freeze.

Freezes the object.
public EnumSet<TimeZoneFormat.ParseOption>

Returns:

the default parse options.
getDefaultParseOptions
()

Returns the default parse options used by this TimeZoneFormat instance.

public String

Returns:

the decimal digits for localized GMT format.
getGMTOffsetDigits
()

Returns the decimal digit characters used for localized GMT format in a single string containing from 0 to 9 in the ascending order.

public String
getGMTOffsetPattern(TimeZoneFormat.GMTOffsetPatternType
the offset pattern enum
type
)

Returns the offset pattern used for localized GMT format.

public String

Returns:

the localized GMT format pattern.
getGMTPattern
()

Returns the localized GMT format pattern.

public String

Returns:

the localized GMT string string for GMT(UTC) itself.
getGMTZeroFormat
()

Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).

public static TimeZoneFormat

Returns:

a frozen instance of TimeZoneFormat for the given locale.
getInstance
(ULocale
the locale.
locale
)

Returns a frozen instance of TimeZoneFormat for the given locale.

public static TimeZoneFormat

Returns:

a frozen instance of TimeZoneFormat for the given locale.
getInstance
(Locale
the Locale.
locale
)

Returns a frozen instance of TimeZoneFormat for the given java.util.Locale.

private synchronized String

Returns:

the target region
getTargetRegion
()

Private method returning the target region.

private TimeZoneFormat.TimeType

Returns:

the time type (unknown/standard/daylight)
getTimeType
(TimeZoneNames.NameType
the name type
nameType
)

Returns the time type for the given name type

private TimeZone

Returns:

A TimeZone with the given offset
getTimeZoneForOffset
(int
the offset
offset
)

Creates an instance of TimeZone for the given offset

private TimeZoneGenericNames

Returns:

the instance of TimeZoneGenericNames used by this object.
getTimeZoneGenericNames
()

Private method returning the instance of TimeZoneGenericNames used by this object.

private String

Returns:

A time zone ID
getTimeZoneID
(String
the time zone ID or null
tzID
,
String
the meta zone ID or null
mzID
)

Private method returns a time zone ID. If tzID is not null, the value of tzID is returned.

public TimeZoneNames

Returns:

the time zone display name data.
getTimeZoneNames
()

Returns the time zone display name data used by this instance.

private TimeZoneNames

Returns:

an instance of TZDBTimeZoneNames.
getTZDBTimeZoneNames
()

Private method returning the instance of TZDBTimeZoneNames.

private void
initGMTOffsetPatterns(String[]
patterns, String[4]
gmtOffsetPatterns
)

Initialize localized GMT format offset hour/min/sec patterns.

private void
initGMTPattern(String
the localized GMT pattern string such as "GMT {0}"
gmtPattern
)

Parses the localized GMT pattern string and initialize localized gmt pattern fields including _gmtPatternTokens.

public boolean
isFrozen()

Implements com.ibm.icu.util.Freezable.isFrozen.

Determines whether the object has been frozen or not.
public TimeZone

Returns:

A TimeZone, or null if the input could not be parsed.
parse
(TimeZoneFormat.Style
the format style.
style
,
String
the text contains a time zone string at the position.
text
,
ParsePosition
the position.
pos
,
EnumSet<TimeZoneFormat.ParseOption>
the parse options.
options
,
Output<TimeZoneFormat.TimeType>
The output argument for receiving the time type (standard/daylight/unknown), or specify null if the information is not necessary.
timeType
)

Returns a TimeZone by parsing the time zone string according to the parse position, the style and the parse options.

public TimeZone

Returns:

A TimeZone, or null if the input could not be parsed.
parse
(TimeZoneFormat.Style
the format style
style
,
String
the text contains a time zone string at the position.
text
,
ParsePosition
the position.
pos
,
Output<TimeZoneFormat.TimeType>
The output argument for receiving the time type (standard/daylight/unknown), or specify null if the information is not necessary.
timeType
)

Returns a TimeZone by parsing the time zone string according to the parse position, the style and the default parse options.

public final TimeZone

Returns:

A TimeZone, or null if the input could not be parsed.
parse
(String
the text contains a time zone string at the position.
text
,
ParsePosition
the position.
pos
)

Returns a TimeZone by parsing the time zone string according to the given parse position.

public final TimeZone

Returns:

A TimeZone.
parse
(String
the time zone string
text
)

Returns a TimeZone for the given text.

private static int

Returns:

Parsed offset, 0 or positive number.
parseAbuttingAsciiOffsetFields
(String
The text contains a sequence of ASCII digits
text
,
ParsePosition
The parse position
pos
,
TimeZoneFormat.OffsetFields
The minimum Fields to be parsed
minFields
,
TimeZoneFormat.OffsetFields
The maximum Fields to be parsed
maxFields
,
boolean
true if hours field must be width of 2
fixedHourWidth
)

Parses offset represented by contiguous ASCII digits

Note

This method expects the input position is already at the start of ASCII digits and does not parse sign (+/-).

private int

Returns:

the parsed offset in milliseconds.
parseAbuttingOffsetFields
(String
the input text
text
,
int
the start index
start
,
int[]
the parsed length, or 0 on failure
parsedLen
)

Parses abutting localized GMT offset fields (such as 0800) into offset.

private static int

Returns:

Parsed offset, 0 or positive number.
parseAsciiOffsetFields
(String
The text
text
,
ParsePosition
The parse position
pos
,
char
The separator character
sep
,
TimeZoneFormat.OffsetFields
The minimum Fields to be parsed
minFields
,
TimeZoneFormat.OffsetFields
The maximum Fields to be parsed
maxFields
)

Parses offset represented by ASCII digits and separators.

private int

Returns:

the parsed offset in milliseconds.
parseDefaultOffsetFields
(String
the input text
text
,
int
the start index
start
,
char
the separator character, e.g.
separator
,
int[]
the parsed length, or 0 on failure.
parsedLen
)

Parses the input GMT offset fields with the default offset pattern.

private String

Returns:

The zone ID for the parsed exemplar location.
parseExemplarLocation
(String
the text contains an exemplar location string at the position.
text
,
ParsePosition
the position.
pos
)

Parse an exemplar location string.

public Object
parseObject(String
A String, part of which should be parsed.
source
,
ParsePosition
A ParsePosition object with index and error index information as described above.
pos
)

Implements abstract java.text.Format.parseObject.

Parses text from a string to produce an object.
private int

Returns:

the parsed offset in milliseconds.
parseOffsetDefaultLocalizedGMT
(String
the input text
text
,
int
the start index
start
,
int[]
the parsed length, or 0 on failure
parsedLen
)

Parses the input text using the default format patterns (e.g. "UTC{0}").

private int

Returns:

the parsed offset in milliseconds.
parseOffsetFields
(String
the input text
text
,
int
the start index
start
,
boolean
true if this is a short format - currently not used
isShort
,
int[]
the parsed length, or 0 on failure.
parsedLen
)

Parses localized GMT offset fields into offset.

private int

Returns:

parsed length
parseOffsetFieldsWithPattern
(String
the input text
text
,
int
the start index
start
,
Object[]
the pattern (already itemized)
patternItems
,
boolean
true if hours field is parsed as a single digit
forceSingleHourDigit
,
int[]
receives the parsed hours/minutes/seconds
fields
)

Parses localized GMT offset fields with the given pattern

private int

Returns:

the integer value parsed
parseOffsetFieldWithLocalizedDigits
(String
the text
text
,
int
the start offset
start
,
int
the minimum number of required digits
minDigits
,
int
the maximum number of digits
maxDigits
,
int
the minimum value
minVal
,
int
the maximum value
maxVal
,
int[]
the actual parsed length is set to parsedLen[0], must not be null.
parsedLen
)

Reads an offset field value.

public final int

Returns:

the offset from GMT(UTC) in milliseconds for the given ISO 8601 style time zone string.
parseOffsetISO8601
(String
the text contains ISO 8601 style time zone string (e.g. "-08", "-0800", "-08:00", and "Z") at the position.
text
,
ParsePosition
the position.
pos
)

Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 basic or extended time zone string.

private static int

Returns:

the offset from GMT(UTC) in milliseconds for the given ISO 8601 style time zone string.
parseOffsetISO8601
(String
the text contains ISO 8601 style time zone string (e.g. "-08", "-08:00", "Z") at the position.
text
,
ParsePosition
the position.
pos
,
boolean
true if parsing the text as ISO 8601 extended offset format (e.g. "-08:00"), or false to evaluate the text as basic format.
extendedOnly
,
Output<Boolean>
receiving if the parsed zone string contains offset digits.
hasDigitOffset
)

Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 time zone string (basic format, extended format, or UTC indicator).

public int

Returns:

the offset from GMT(UTC) in milliseconds for the given localized GMT offset format string.
parseOffsetLocalizedGMT
(String
the text contains a localized GMT offset string at the position.
text
,
ParsePosition
the position.
pos
)

Returns offset from GMT(UTC) in milliseconds for the given localized GMT offset format string.

private int

Returns:

the offset from GMT(UTC) in milliseconds for the given localized GMT offset format string.
parseOffsetLocalizedGMT
(String
the text contains a localized GMT offset string at the position.
text
,
ParsePosition
the position.
pos
,
boolean
true if this parser to try the short format first
isShort
,
Output<Boolean>
receiving if the parsed zone string contains offset digits.
hasDigitOffset
)

Returns offset from GMT(UTC) in milliseconds for the given localized GMT offset format string.

private int

Returns:

the parsed offset in milliseconds.
parseOffsetLocalizedGMTPattern
(String
the input text
text
,
int
the start index
start
,
boolean
true if the short localized GMT format is parsed.
isShort
,
int[]
the parsed length, or 0 on failure.
parsedLen
)

Parse localized GMT format generated by the pattern used by this formatter, except GMT Zero format.

private static Object[]

Returns:

An array of Object. Each array entry is either String (representing pattern literal) or GMTOffsetField (hour/min/sec field)
parseOffsetPattern
(String
the offset pattern string
pattern
,
String
the required pattern letters such as "Hm"
letters
)

Parse the GMT offset pattern into runtime optimized format

public int

Returns:

the offset from GMT(UTC) in milliseconds for the given short localized GMT offset format string.
parseOffsetShortLocalizedGMT
(String
the text contains a short localized GMT offset string at the position.
text
,
ParsePosition
the position.
pos
)

Returns offset from GMT(UTC) in milliseconds for the given short localized GMT offset format string.

private static String

Returns:

The zone ID for the parsed short zone ID.
parseShortZoneID
(String
the text contains a time zone ID string at the position.
text
,
ParsePosition
the position.
pos
)

Parse a short zone ID.

private int

Returns:

the integer value of the parsed digit, or -1 on failure.
parseSingleLocalizedDigit
(String
the text
text
,
int
the start index
start
,
int[]
the actual length read from the text the start index is not a decimal number.
len
)

Reads a single decimal digit, either localized digits used by this object or any Unicode numeric character.

private static String

Returns:

The zone ID parsed.
parseZoneID
(String
the text contains a time zone ID string at the position.
text
,
ParsePosition
the position.
pos
)

Parse a zone ID.

private void
readObject(ObjectInputStream
the object input stream
ois
)

public TimeZoneFormat

Returns:

this object.
setDefaultParseOptions
(EnumSet<TimeZoneFormat.ParseOption>
the default parse options.
options
)

Sets the default parse options.

public TimeZoneFormat

Returns:

this object.
setGMTOffsetDigits
(String
a string contains the decimal digit characters from 0 to 9 n the ascending order.
digits
)

Sets the decimal digit characters used for localized GMT format.

public TimeZoneFormat

Returns:

this object.
setGMTOffsetPattern
(TimeZoneFormat.GMTOffsetPatternType
the offset pattern.
type
,
String
the pattern string.
pattern
)

Sets the offset pattern for the given offset type.

public TimeZoneFormat

Returns:

this object.
setGMTPattern
(String
the localized GMT format pattern string
pattern
)

Sets the localized GMT format pattern.

public TimeZoneFormat

Returns:

this object.
setGMTZeroFormat
(String
the localized GMT format string for GMT(UTC).
gmtZeroFormat
)

Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).

public TimeZoneFormat

Returns:

this object.
setTimeZoneNames
(TimeZoneNames
the time zone display name data.
tznames
)

Sets the time zone display name data to this instance.

private static String[]

Returns:

the array of code points in String[]
toCodePoints
(String
the string
str
)

Break input String into String[].

private static String

Returns:

the offset pattern including only hours field
truncateOffsetPattern
(String
the offset pattern including hours and minutes fields
offsetHM
)

Truncates minutes field from the offset pattern with hour/minute

private static String

Returns:

the unquoted pattern string
unquote
(String
the pattern
s
)

Unquotes the message format style pattern.

private void
writeObject(ObjectOutputStream
the object output stream
oos
)

Inherited from com.ibm.icu.text.UFormat:
getLocalesetLocale