APIdia Launch Partner
Top Description Fields Constructors Methods
sun.util.calendar

public Class ZoneInfo

extends TimeZone
Class Inheritance
Imports
java.io.IOException, .ObjectInputStream, java.util.Date, .Map, .SimpleTimeZone, .TimeZone, java.util.stream.Stream

ZoneInfo is an implementation subclass of TimeZone that represents GMT offsets and daylight saving time transitions of a time zone.

The daylight saving time transitions are described in the transitions table consisting of a chronological sequence of transitions of GMT offset and/or daylight saving time changes. Since all transitions are represented in UTC, in theory, ZoneInfo can be used with any calendar systems except for the getOffset method that takes Gregorian calendar date fields.

This table covers transitions from 1900 until 2100 (as of version 23), Before 1900, it assumes that there was no daylight saving time and the getOffset methods always return the getRawOffset value. No Local Mean Time is supported. If a specified date is beyond the transition table and this time zone is supposed to observe daylight saving time in 2100, it delegates operations to a SimpleTimeZone object created using the daylight saving time schedule as of 2100.

The date items, transitions, GMT offset(s), etc. are read from a database file. See ZoneInfoFile for details.

Since
1.4
See Also
java.util.SimpleTimeZone

Field Summary

Modifier and TypeField and Description
private int
checksum

A CRC32 value of all pairs of transition time (in milliseconds in long) in local time and its GMT offset (in seconds in int) in the chronological order.

private transient boolean
dirty

True if the object has been modified after its instantiation.

private static final long
private static final int
private int
dstSavings

The amount of time in milliseconds saved during daylight saving time.

private transient SimpleTimeZone
private static final long
private int[]
offsets

This array holds all unique offset values in milliseconds.

private int
rawOffset

The raw GMT offset in milliseconds between this zone and GMT.

private int
rawOffsetDiff

Difference in milliseconds from the original GMT offset in case the raw offset value has been modified by calling setRawOffset.

private static final long
private int[]
simpleTimeZoneParams

SimpleTimeZone parameter values.

private static final int
private static final int
private long[]
transitions

This array describes transitions of GMT offsets of this time zone, including both raw offset changes and daylight saving time changes.

private static final int
private static final int
private boolean
willGMTOffsetChange

True if the raw GMT offset value would change after the time zone data has been generated; false, otherwise.

Inherited from java.util.TimeZone:
LONGSHORT

Constructor Summary

AccessConstructor and Description
public
ZoneInfo()

A constructor.

public
ZoneInfo(String ID, int rawOffset)

A Constructor for CustomID.

pack-priv
ZoneInfo(String
time zone name
ID
,
int
GMT offset in milliseconds
rawOffset
,
int
daylight saving value in milliseconds or 0 (zero) if this time zone doesn't observe Daylight Saving Time.
dstSavings
,
int
CRC32 value with all transitions table entry values
checksum
,
long[]
transition table
transitions
,
int[]
offset value table
offsets
,
int[]
parameter values for constructing SimpleTimeZone
simpleTimeZoneParams
,
boolean
the value of willGMTOffsetChange
willGMTOffsetChange
)

Constructs a ZoneInfo instance.

Method Summary

Modifier and TypeMethod and Description
public static Stream<String>

Returns:

a stream of time zone IDs.
availableIDs
()

Hides java.util.TimeZone.availableIDs.

Gets all available IDs supported in the Java run-time.

public static Stream<String>

Returns:

a stream of time zone IDs.
availableIDs
(int
the GMT offset in milliseconds. This value should not include any daylight saving time.
rawOffset
)

Hides java.util.TimeZone.availableIDs.

Gets all available IDs that have the same value as the specified raw GMT offset.

public Object
clone()

Overrides java.util.TimeZone.clone.

Returns a copy of this ZoneInfo.

public boolean

Returns:

true if given object is same as this ZoneInfo object, false otherwise.
equals
(Object
the object to be compared with
obj
)

Overrides java.lang.Object.equals.

Compares the equity of two ZoneInfo objects.

public static Map<String, String>

Returns:

the Map that holds the mappings from alias time zone IDs to their standard time zone IDs, or null if ZoneInfoMappings file is not available.
getAliasTable
()

Returns a Map from alias time zone IDs to their standard time zone IDs.

public static String[]

Returns:

an array of time zone IDs.
getAvailableIDs
()

Hides java.util.TimeZone.getAvailableIDs.

Gets all available IDs supported in the Java run-time.

public static String[]

Returns:

an array of time zone IDs.
getAvailableIDs
(int
the GMT offset in milliseconds. This value should not include any daylight saving time.
rawOffset
)

Hides java.util.TimeZone.getAvailableIDs.

Gets all available IDs that have the same value as the specified raw GMT offset.

public int

Returns:

the number of milliseconds the time is advanced with respect to standard time when daylight saving time is in effect.
getDSTSavings
()

Overrides java.util.TimeZone.getDSTSavings.

Returns the amount of time in milliseconds that the clock is advanced during daylight saving time is in effect in its last daylight saving time rule.

private int
private synchronized SimpleTimeZone
getLastRule()

Returns a SimpleTimeZone object representing the last GMT offset and DST schedule or null if this time zone doesn't observe DST.

public SimpleTimeZone

Returns:

a SimpleTimeZone object or null if this time zone doesn't observe DST.
getLastRuleInstance
()

Returns a SimpleTimeZone object that represents the last known daylight saving time rules.

public int

Returns:

the milliseconds to add to UTC to get local wall time
getOffset
(long
the milliseconds in UTC
date
)

Overrides java.util.TimeZone.getOffset.

Returns the difference in milliseconds between local time and UTC of given time, taking into account both the raw offset and the effect of daylight savings.

public int

Returns:

The milliseconds to add to UTC to get local time.
getOffset
(int
The era of the given date. The value must be either GregorianCalendar.AD or GregorianCalendar.BC.
era
,
int
The year in the given date.
year
,
int
The month in the given date. Month is 0-based. e.g., 0 for January.
month
,
int
The day-in-month of the given date.
day
,
int
The day-of-week of the given date.
dayOfWeek
,
int
The milliseconds in day in standard local time.
milliseconds
)

Implements abstract java.util.TimeZone.getOffset.

Returns the difference in milliseconds between local time and UTC, taking into account both the raw offset and the effect of daylight savings, for the specified date and time.

public int
getOffsets(long utc, int[] offsets)

Hides java.util.TimeZone.getOffsets.

Gets the raw GMT offset and the amount of daylight saving of this time zone at the given time.

private int
getOffsets(long date, int[] offsets, int type)

public int
getOffsetsByStandard(long standard, int[] offsets)

public int
getOffsetsByWall(long wall, int[] offsets)

public int

Returns:

the GMT offset value in milliseconds to add to UTC time to get local standard time
getRawOffset
()

Implements abstract java.util.TimeZone.getRawOffset.

Returns the GMT offset of the current date.

public static TimeZone

Returns:

the specified ZoneInfo object, or null if there is no time zone of the ID.
getTimeZone
(String
the ID for a ZoneInfo. See TimeZone for detail.
ID
)

Hides java.util.TimeZone.getTimeZone.

Gets the ZoneInfo for the given ID.

private int
getTransitionIndex(long date, int type)

public int

Returns:

a hash code of this time zone
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value calculated from the GMT offset and transitions.

public boolean

Returns:

true if the given TimeZone has the same GMT offset and transition information; false, otherwise.
hasSameRules
(TimeZone
the ZoneInfo object to be compared with
other
)

Overrides java.util.TimeZone.hasSameRules.

Returns true if this zone has the same raw GMT offset value and transition table as another zone info.

public boolean
inDaylightTime(Date date)

Implements abstract java.util.TimeZone.inDaylightTime.

Queries if the specified date is in Daylight Saving Time.

public boolean
public boolean
observesDaylightTime()

Overrides java.util.TimeZone.observesDaylightTime.

Returns true if this TimeZone is currently in Daylight Saving Time, or if a transition from Standard Time to Daylight Saving Time occurs at any future time.

private void
public synchronized void
setRawOffset(int
the base time zone offset to GMT.
offsetMillis
)

Implements abstract java.util.TimeZone.setRawOffset.

Sets the base time zone offset from GMT.

public String

Returns:

the string
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this time zone.

public boolean
useDaylightTime()

Implements abstract java.util.TimeZone.useDaylightTime.

Queries if this time zone uses Daylight Saving Time in the last known rule.

Inherited from java.util.TimeZone:
getDefaultgetDisplayNamegetDisplayNamegetDisplayNamegetDisplayNamegetIDgetTimeZonesetDefaultsetIDtoZoneId

Field Detail

checksumback to summary
private int checksum

A CRC32 value of all pairs of transition time (in milliseconds in long) in local time and its GMT offset (in seconds in int) in the chronological order. Byte values of each long and int are taken in the big endian order (i.e., MSB to LSB).

dirtyback to summary
private transient boolean dirty

True if the object has been modified after its instantiation.

DST_MASKback to summary
private static final long DST_MASK
DST_NSHIFTback to summary
private static final int DST_NSHIFT
dstSavingsback to summary
private int dstSavings

The amount of time in milliseconds saved during daylight saving time. If useDaylight is false, this value is 0.

lastRuleback to summary
private transient SimpleTimeZone lastRule
OFFSET_MASKback to summary
private static final long OFFSET_MASK
offsetsback to summary
private int[] offsets

This array holds all unique offset values in milliseconds. Index values to this array are stored in the transitions array elements.

rawOffsetback to summary
private int rawOffset

The raw GMT offset in milliseconds between this zone and GMT. Negative offsets are to the west of Greenwich. To obtain local standard time, add the offset to GMT time.

rawOffsetDiffback to summary
private int rawOffsetDiff

Difference in milliseconds from the original GMT offset in case the raw offset value has been modified by calling setRawOffset. The initial value is 0.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.TimeZone.serialVersionUID.

Annotations
@Serial
simpleTimeZoneParamsback to summary
private int[] simpleTimeZoneParams

SimpleTimeZone parameter values. It has to have either 8 for the 11-argument SimpleTimeZone constructor or 10 for the 13-argument SimpleTimeZone constructor parameters.

STANDARD_TIMEback to summary
private static final int STANDARD_TIME
TRANSITION_NSHIFTback to summary
private static final int TRANSITION_NSHIFT
transitionsback to summary
private long[] transitions

This array describes transitions of GMT offsets of this time zone, including both raw offset changes and daylight saving time changes. A long integer consists of four bit fields.

  • The most significant 52-bit field represents transition time in milliseconds from Gregorian January 1 1970, 00:00:00 GMT.
  • The next 4-bit field is reserved and must be 0.
  • The next 4-bit field is an index value to offsets[] for the amount of daylight saving at the transition. If this value is zero, it means that no daylight saving, not the index value zero.
  • The least significant 4-bit field is an index value to offsets[] for total GMT offset at the transition.
If this time zone doesn't observe daylight saving time and has never changed any GMT offsets in the past, this value is null.
UTC_TIMEback to summary
private static final int UTC_TIME
WALL_TIMEback to summary
private static final int WALL_TIME
willGMTOffsetChangeback to summary
private boolean willGMTOffsetChange

True if the raw GMT offset value would change after the time zone data has been generated; false, otherwise. The default value is false.

Constructor Detail

ZoneInfoback to summary
public ZoneInfo()

A constructor.

ZoneInfoback to summary
public ZoneInfo(String ID, int rawOffset)

A Constructor for CustomID.

ZoneInfoback to summary
pack-priv ZoneInfo(String ID, int rawOffset, int dstSavings, int checksum, long[] transitions, int[] offsets, int[] simpleTimeZoneParams, boolean willGMTOffsetChange)

Constructs a ZoneInfo instance.

Parameters
ID:String

time zone name

rawOffset:int

GMT offset in milliseconds

dstSavings:int

daylight saving value in milliseconds or 0 (zero) if this time zone doesn't observe Daylight Saving Time.

checksum:int

CRC32 value with all transitions table entry values

transitions:long[]

transition table

offsets:int[]

offset value table

simpleTimeZoneParams:int[]

parameter values for constructing SimpleTimeZone

willGMTOffsetChange:boolean

the value of willGMTOffsetChange

Method Detail

availableIDsback to summary
public static Stream<String> availableIDs()

Hides java.util.TimeZone.availableIDs.

Gets all available IDs supported in the Java run-time.

Returns:Stream<String>

a stream of time zone IDs.

availableIDsback to summary
public static Stream<String> availableIDs(int rawOffset)

Hides java.util.TimeZone.availableIDs.

Gets all available IDs that have the same value as the specified raw GMT offset.

Parameters
rawOffset:int

the GMT offset in milliseconds. This value should not include any daylight saving time.

Returns:Stream<String>

a stream of time zone IDs.

cloneback to summary
public Object clone()

Overrides java.util.TimeZone.clone.

Returns a copy of this ZoneInfo.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Compares the equity of two ZoneInfo objects.

Parameters
obj:Object

the object to be compared with

Returns:boolean

true if given object is same as this ZoneInfo object, false otherwise.

getAliasTableback to summary
public static Map<String, String> getAliasTable()

Returns a Map from alias time zone IDs to their standard time zone IDs.

Returns:Map<String, String>

the Map that holds the mappings from alias time zone IDs to their standard time zone IDs, or null if ZoneInfoMappings file is not available.

getAvailableIDsback to summary
public static String[] getAvailableIDs()

Hides java.util.TimeZone.getAvailableIDs.

Gets all available IDs supported in the Java run-time.

Returns:String[]

an array of time zone IDs.

getAvailableIDsback to summary
public static String[] getAvailableIDs(int rawOffset)

Hides java.util.TimeZone.getAvailableIDs.

Gets all available IDs that have the same value as the specified raw GMT offset.

Parameters
rawOffset:int

the GMT offset in milliseconds. This value should not include any daylight saving time.

Returns:String[]

an array of time zone IDs.

getDSTSavingsback to summary
public int getDSTSavings()

Overrides java.util.TimeZone.getDSTSavings.

Returns the amount of time in milliseconds that the clock is advanced during daylight saving time is in effect in its last daylight saving time rule.

Returns:int

the number of milliseconds the time is advanced with respect to standard time when daylight saving time is in effect.

getLastRawOffsetback to summary
private int getLastRawOffset()
getLastRuleback to summary
private synchronized SimpleTimeZone getLastRule()

Returns a SimpleTimeZone object representing the last GMT offset and DST schedule or null if this time zone doesn't observe DST.

getLastRuleInstanceback to summary
public SimpleTimeZone getLastRuleInstance()

Returns a SimpleTimeZone object that represents the last known daylight saving time rules.

Returns:SimpleTimeZone

a SimpleTimeZone object or null if this time zone doesn't observe DST.

getOffsetback to summary
public int getOffset(long date)

Overrides java.util.TimeZone.getOffset.

Returns the difference in milliseconds between local time and UTC of given time, taking into account both the raw offset and the effect of daylight savings.

Parameters
date:long

the milliseconds in UTC

Returns:int

the milliseconds to add to UTC to get local wall time

getOffsetback to summary
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)

Implements abstract java.util.TimeZone.getOffset.

Returns the difference in milliseconds between local time and UTC, taking into account both the raw offset and the effect of daylight savings, for the specified date and time. This method assumes that the start and end month are distinct. This method assumes a Gregorian calendar for calculations.

Note

In general, clients should use Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET) instead of calling this method.

Parameters
era:int

The era of the given date. The value must be either GregorianCalendar.AD or GregorianCalendar.BC.

year:int

The year in the given date.

month:int

The month in the given date. Month is 0-based. e.g., 0 for January.

day:int

The day-in-month of the given date.

dayOfWeek:int

The day-of-week of the given date.

milliseconds:int

The milliseconds in day in standard local time.

Returns:int

The milliseconds to add to UTC to get local time.

getOffsetsback to summary
public int getOffsets(long utc, int[] offsets)

Hides java.util.TimeZone.getOffsets.

Doc from java.util.TimeZone.getOffsets.

Gets the raw GMT offset and the amount of daylight saving of this time zone at the given time.

getOffsetsback to summary
private int getOffsets(long date, int[] offsets, int type)
getOffsetsByStandardback to summary
public int getOffsetsByStandard(long standard, int[] offsets)
getOffsetsByWallback to summary
public int getOffsetsByWall(long wall, int[] offsets)
getRawOffsetback to summary
public int getRawOffset()

Implements abstract java.util.TimeZone.getRawOffset.

Returns the GMT offset of the current date. This GMT offset value is not modified during Daylight Saving Time.

Returns:int

the GMT offset value in milliseconds to add to UTC time to get local standard time

getTimeZoneback to summary
public static TimeZone getTimeZone(String ID)

Hides java.util.TimeZone.getTimeZone.

Gets the ZoneInfo for the given ID.

Parameters
ID:String

the ID for a ZoneInfo. See TimeZone for detail.

Returns:TimeZone

the specified ZoneInfo object, or null if there is no time zone of the ID.

getTransitionIndexback to summary
private int getTransitionIndex(long date, int type)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value calculated from the GMT offset and transitions.

Returns:int

a hash code of this time zone

hasSameRulesback to summary
public boolean hasSameRules(TimeZone other)

Overrides java.util.TimeZone.hasSameRules.

Returns true if this zone has the same raw GMT offset value and transition table as another zone info. If the specified TimeZone object is not a ZoneInfo instance, this method returns true if the specified TimeZone object has the same raw GMT offset value with no daylight saving time.

Parameters
other:TimeZone

the ZoneInfo object to be compared with

Returns:boolean

true if the given TimeZone has the same GMT offset and transition information; false, otherwise.

inDaylightTimeback to summary
public boolean inDaylightTime(Date date)

Implements abstract java.util.TimeZone.inDaylightTime.

Queries if the specified date is in Daylight Saving Time.

isDirtyback to summary
public boolean isDirty()
observesDaylightTimeback to summary
public boolean observesDaylightTime()

Overrides java.util.TimeZone.observesDaylightTime.

Doc from java.util.TimeZone.observesDaylightTime.

Returns true if this TimeZone is currently in Daylight Saving Time, or if a transition from Standard Time to Daylight Saving Time occurs at any future time.

The default implementation returns true if useDaylightTime() or inDaylightTime(new Date()) returns true.

Annotations
@Override
readObjectback to summary
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
Annotations
@Serial
setRawOffsetback to summary
public synchronized void setRawOffset(int offsetMillis)

Implements abstract java.util.TimeZone.setRawOffset.

Sets the base time zone offset from GMT. This operation modifies all the transitions of this ZoneInfo object, including historical ones, if applicable.

Parameters
offsetMillis:int

the base time zone offset to GMT.

See Also
getRawOffset
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this time zone.

Returns:String

the string

useDaylightTimeback to summary
public boolean useDaylightTime()

Implements abstract java.util.TimeZone.useDaylightTime.

Queries if this time zone uses Daylight Saving Time in the last known rule.