ZoneChronoDateTime
is an immutable representation of a date-time with a time-zone.
This class stores all date and time fields, to a precision of nanoseconds,
as well as a time-zone and zone offset.
The purpose of storing the time-zone is to distinguish the ambiguous case where the local time-line overlaps, typically as a result of the end of daylight time. Information about the local-time can be obtained using methods on the time-zone.
Implementation Specification
This class is immutable and thread-safe.
Modifier and Type | Field and Description |
---|---|
private final transient ChronoLocalDateTimeImpl | dateTime
The local date-time. |
private final transient ZoneOffset | offset
The zone offset. |
private static final long | serialVersionUID
Serialization version. |
private final transient ZoneId | zone
The zone ID. |
Access | Constructor and Description |
---|---|
private | ChronoZonedDateTimeImpl(ChronoLocalDateTimeImpl<D>
the date-time, not null dateTime, ZoneOffset the zone offset, not null offset, ZoneId the zone ID, not null zone)Constructor. |
Modifier and Type | Method and Description |
---|---|
private ChronoZonedDateTimeImpl | |
pack-priv static <R extends ChronoLocalDate> ChronoZonedDateTimeImpl | Returns: the date-time checked and cast toChronoZonedDateTimeImpl , not nullthe chronology to check for, not null chrono, Temporal a date-time to cast, not null temporal)Casts the |
public boolean | equals(Object
the object to check, null returns false obj)Overrides java. Implements java. Checks if this date-time is equal to another date-time. |
public ZoneOffset | getOffset()
Implements java. Gets the zone offset, such as '+01:00'. |
public ZoneId | getZone()
Implements java. Gets the zone ID, such as 'Europe/Paris'. |
public int | hashCode()
Overrides java. Implements java. A hash code for this date-time. |
public boolean | isSupported(TemporalField
the field to check, null returns false field)Implements java. Checks if the specified field is supported. |
pack-priv static <R extends ChronoLocalDate> ChronoZonedDateTime | Returns: the zoned date-time, not nullthe local date-time, not null localDateTime, ZoneId the zone identifier, not null zone, ZoneOffset the zone offset, null if no preference preferredOffset)Obtains an instance from a local date-time using the preferred offset if possible. |
pack-priv static ChronoZonedDateTimeImpl | Returns: the zoned date-time, not nullthe chronology, not null chrono, Instant the instant, not null instant, ZoneId the zone identifier, not null zone)Obtains an instance from an instant using the specified time-zone. |
public ChronoZonedDateTime | plus(long
the amount of the specified unit to add, may be negative amountToAdd, TemporalUnit the unit of the amount to add, not null unit)Implements java. Returns an object of the same type as this object with the specified period added. |
pack-priv static ChronoZonedDateTime | |
private void | |
public ChronoLocalDateTime | toLocalDateTime()
Implements java. Gets the local date-time part of this date-time. |
public String | toString()
Overrides java. Implements java. Outputs this date-time as a |
public long | until(Temporal
the end temporal, exclusive, converted to be of the
same type as this object, not null endExclusive, TemporalUnit the unit to measure the amount in, not null unit)Implements java. Calculates the amount of time until another temporal in terms of the specified unit. |
public ChronoZonedDateTime | with(TemporalField
the field to set in the result, not null field, long the new value of the field in the result newValue)Implements java. Returns an object of the same type as this object with the specified field altered. |
public ChronoZonedDateTime | withEarlierOffsetAtOverlap()
Implements java. Returns a copy of this date-time changing the zone offset to the earlier of the two valid offsets at a local time-line overlap. |
public ChronoZonedDateTime | withLaterOffsetAtOverlap()
Implements java. Returns a copy of this date-time changing the zone offset to the later of the two valid offsets at a local time-line overlap. |
public ChronoZonedDateTime | withZoneSameInstant(ZoneId
the time-zone to change to, not null zone)Implements java. Returns a copy of this date-time with a different time-zone, retaining the instant. |
public ChronoZonedDateTime | withZoneSameLocal(ZoneId
the time-zone to change to, not null zone)Implements java. Returns a copy of this date-time with a different time-zone, retaining the local date-time if possible. |
pack-priv void | |
private Object | Returns: the instance ofSer , not nullWrites the ChronoZonedDateTime using a dedicated serialized form. |
dateTime | back to summary |
---|---|
private final transient ChronoLocalDateTimeImpl<D> dateTime The local date-time. |
offset | back to summary |
---|---|
private final transient ZoneOffset offset The zone offset. |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Serialization version. |
zone | back to summary |
---|---|
private final transient ZoneId zone The zone ID. |
ChronoZonedDateTimeImpl | back to summary |
---|---|
private ChronoZonedDateTimeImpl(ChronoLocalDateTimeImpl<D> dateTime, ZoneOffset offset, ZoneId zone) Constructor.
|
create | back to summary |
---|---|
private ChronoZonedDateTimeImpl Obtains an instance from an
|
ensureValid | back to summary |
---|---|
pack-priv static <R extends ChronoLocalDate> ChronoZonedDateTimeImpl Casts the
|
equals | back to summary |
---|---|
public boolean equals(Object obj) Overrides java. Implements java. Doc from java. Checks if this date-time is equal to another date-time.
The comparison is based on the offset date-time and the zone.
To compare for the same instant on the time-line, use |
getOffset | back to summary |
---|---|
public ZoneOffset getOffset() Implements java. Doc from java. Gets the zone offset, such as '+01:00'. This is the offset of the local date-time from UTC/Greenwich.
|
getZone | back to summary |
---|---|
public ZoneId getZone() Implements java. Doc from java. Gets the zone ID, such as 'Europe/Paris'. This returns the stored time-zone id used to determine the time-zone rules. |
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Implements java. Doc from java. A hash code for this date-time.
|
isSupported | back to summary |
---|---|
public boolean isSupported(TemporalField field) Implements java. Doc from java. Checks if the specified field is supported.
This checks if the specified field can be queried on this date-time.
If false, then calling the
The set of supported fields is defined by the chronology and normally includes
all
If the field is not a
|
ofBest | back to summary |
---|---|
pack-priv static <R extends ChronoLocalDate> ChronoZonedDateTime Obtains an instance from a local date-time using the preferred offset if possible.
|
ofInstant | back to summary |
---|---|
pack-priv static ChronoZonedDateTimeImpl Obtains an instance from an instant using the specified time-zone.
|
plus | back to summary |
---|---|
public ChronoZonedDateTime Implements java. Doc from java. Returns an object of the same type as this object with the specified period added.
This method returns a new object based on this one with the specified period added.
For example, on a In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st January, then adding one month would be unclear. In cases like this, the field is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.
|
readExternal | back to summary |
---|---|
pack-priv static ChronoZonedDateTime |
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws InvalidObjectException Defend against malicious streams.
|
toLocalDateTime | back to summary |
---|---|
public ChronoLocalDateTime Implements java. Doc from java. Gets the local date-time part of this date-time. This returns a local date with the same year, month and day as this date-time.
|
toString | back to summary |
---|---|
public String toString() Overrides java. Implements java. Doc from java. Outputs this date-time as a The output will include the full zoned date-time. |
until | back to summary |
---|---|
public long until(Temporal endExclusive, TemporalUnit unit) Implements java. Doc from java. Calculates the amount of time until another temporal in terms of the specified unit.
This calculates the amount of time between two temporal objects
in terms of a single The calculation returns a whole number, representing the number of complete units between the two temporals. For example, the amount in hours between the times 11:30 and 13:29 will only be one hour as it is one minute short of two hours.
There are two equivalent ways of using this method.
The first is to invoke this method directly.
The second is to use // these two lines are equivalent temporal = start.until(end, unit); temporal = unit.between(start, end);The choice should be made based on which makes the code more readable. For example, this method allows the number of days between two dates to be calculated: long daysBetween = start.until(end, DAYS); // or alternatively long daysBetween = DAYS.between(start, end);
|
with | back to summary |
---|---|
public ChronoZonedDateTime Implements java. Doc from java. Returns an object of the same type as this object with the specified field altered.
This returns a new object based on this one with the value for the specified field changed.
For example, on a In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st January, then changing the month to February would be unclear. In cases like this, the field is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.
|
withEarlierOffsetAtOverlap | back to summary |
---|---|
public ChronoZonedDateTime Implements java. Doc from java. Returns a copy of this date-time changing the zone offset to the earlier of the two valid offsets at a local time-line overlap. This method only has any effect when the local time-line overlaps, such as at an autumn daylight savings cutover. In this scenario, there are two valid offsets for the local date-time. Calling this method will return a zoned date-time with the earlier of the two selected.
If this method is called when it is not an overlap, This instance is immutable and unaffected by this method call.
|
withLaterOffsetAtOverlap | back to summary |
---|---|
public ChronoZonedDateTime Implements java. Doc from java. Returns a copy of this date-time changing the zone offset to the later of the two valid offsets at a local time-line overlap. This method only has any effect when the local time-line overlaps, such as at an autumn daylight savings cutover. In this scenario, there are two valid offsets for the local date-time. Calling this method will return a zoned date-time with the later of the two selected.
If this method is called when it is not an overlap, This instance is immutable and unaffected by this method call.
|
withZoneSameInstant | back to summary |
---|---|
public ChronoZonedDateTime Implements java. Doc from java. Returns a copy of this date-time with a different time-zone, retaining the instant. This method changes the time-zone and retains the instant. This normally results in a change to the local date-time. This method is based on retaining the same instant, thus gaps and overlaps in the local time-line have no effect on the result.
To change the offset while keeping the local time,
use
|
withZoneSameLocal | back to summary |
---|---|
public ChronoZonedDateTime Implements java. Doc from java. Returns a copy of this date-time with a different time-zone, retaining the local date-time if possible. This method changes the time-zone and retains the local date-time. The local date-time is only changed if it is invalid for the new zone.
To change the zone and adjust the local date-time,
use This instance is immutable and unaffected by this method call.
|
writeExternal | back to summary |
---|---|
pack-priv void writeExternal(ObjectOutput out) throws IOException |
writeReplace | back to summary |
---|---|
private Object writeReplace() Writes the ChronoZonedDateTime using a dedicated serialized form. |