Top Description Fields Constructors Methods
java.time.chrono

pack-priv final Class ChronoZonedDateTimeImpl<D extends ChronoLocalDate>

extends Object
implements ChronoZonedDateTime<D extends ChronoLocalDate>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.time.chrono.ChronoZonedDateTime, java.lang.Comparable, java.time.temporal.Temporal, java.time.temporal.TemporalAccessor
Type Parameters
<D>
the concrete type for the date of this date-time
Static Imports
java.time.temporal.ChronoUnit.SECONDS

A date-time with a time-zone in the calendar neutral API.

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.

Since
1.8

Field Summary

Modifier and TypeField and Description
private final transient ChronoLocalDateTimeImpl<D>
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.

Constructor Summary

AccessConstructor 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.

Method Summary

Modifier and TypeMethod and Description
private ChronoZonedDateTimeImpl<D>

Returns:

the zoned date-time, validated not null
create
(Instant
the instant to create the date-time from, not null
instant
,
ZoneId
the time-zone to use, validated not null
zone
)

Obtains an instance from an Instant.

pack-priv static <R extends ChronoLocalDate> ChronoZonedDateTimeImpl<R>

Returns:

the date-time checked and cast to ChronoZonedDateTimeImpl, not null
ensureValid
(Chronology
the chronology to check for, not null
chrono
,
Temporal
a date-time to cast, not null
temporal
)

Casts the Temporal to ChronoZonedDateTimeImpl ensuring it bas the specified chronology.

public boolean
equals(Object
the object to check, null returns false
obj
)

Overrides java.lang.Object.equals.

Implements java.time.chrono.ChronoZonedDateTime.equals.

Checks if this date-time is equal to another date-time.

public ZoneOffset
getOffset()

Implements java.time.chrono.ChronoZonedDateTime.getOffset.

Gets the zone offset, such as '+01:00'.

public ZoneId
getZone()

Implements java.time.chrono.ChronoZonedDateTime.getZone.

Gets the zone ID, such as 'Europe/Paris'.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.time.chrono.ChronoZonedDateTime.hashCode.

A hash code for this date-time.

public boolean
isSupported(TemporalField
the field to check, null returns false
field
)

Implements java.time.chrono.ChronoZonedDateTime.isSupported.

Checks if the specified field is supported.

pack-priv static <R extends ChronoLocalDate> ChronoZonedDateTime<R>

Returns:

the zoned date-time, not null
ofBest
(ChronoLocalDateTimeImpl<R>
the 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 null
ofInstant
(Chronology
the 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<D>
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.time.chrono.ChronoZonedDateTime.plus.

Returns an object of the same type as this object with the specified period added.

pack-priv static ChronoZonedDateTime<?>
private void
readObject(ObjectInputStream
the stream to read
s
)

Defend against malicious streams.

public ChronoLocalDateTime<D>
toLocalDateTime()

Implements java.time.chrono.ChronoZonedDateTime.toLocalDateTime.

Gets the local date-time part of this date-time.

public String
toString()

Overrides java.lang.Object.toString.

Implements java.time.chrono.ChronoZonedDateTime.toString.

Outputs this date-time as a String.

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.time.temporal.Temporal.until.

Calculates the amount of time until another temporal in terms of the specified unit.

public ChronoZonedDateTime<D>
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.time.chrono.ChronoZonedDateTime.with.

Returns an object of the same type as this object with the specified field altered.

public ChronoZonedDateTime<D>
withEarlierOffsetAtOverlap()

Implements java.time.chrono.ChronoZonedDateTime.withEarlierOffsetAtOverlap.

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<D>
withLaterOffsetAtOverlap()

Implements java.time.chrono.ChronoZonedDateTime.withLaterOffsetAtOverlap.

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<D>
withZoneSameInstant(ZoneId
the time-zone to change to, not null
zone
)

Implements java.time.chrono.ChronoZonedDateTime.withZoneSameInstant.

Returns a copy of this date-time with a different time-zone, retaining the instant.

public ChronoZonedDateTime<D>
withZoneSameLocal(ZoneId
the time-zone to change to, not null
zone
)

Implements java.time.chrono.ChronoZonedDateTime.withZoneSameLocal.

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 of Ser, not null
writeReplace
()

Writes the ChronoZonedDateTime using a dedicated serialized form.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

dateTimeback to summary
private final transient ChronoLocalDateTimeImpl<D> dateTime

The local date-time.

offsetback to summary
private final transient ZoneOffset offset

The zone offset.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

Annotations
@Serial
zoneback to summary
private final transient ZoneId zone

The zone ID.

Constructor Detail

ChronoZonedDateTimeImplback to summary
private ChronoZonedDateTimeImpl(ChronoLocalDateTimeImpl<D> dateTime, ZoneOffset offset, ZoneId zone)

Constructor.

Parameters
dateTime:ChronoLocalDateTimeImpl<D>

the date-time, not null

offset:ZoneOffset

the zone offset, not null

zone:ZoneId

the zone ID, not null

Method Detail

createback to summary
private ChronoZonedDateTimeImpl<D> create(Instant instant, ZoneId zone)

Obtains an instance from an Instant.

Parameters
instant:Instant

the instant to create the date-time from, not null

zone:ZoneId

the time-zone to use, validated not null

Returns:ChronoZonedDateTimeImpl<D>

the zoned date-time, validated not null

Annotations
@SuppressWarnings:unchecked
ensureValidback to summary
pack-priv static <R extends ChronoLocalDate> ChronoZonedDateTimeImpl<R> ensureValid(Chronology chrono, Temporal temporal)

Casts the Temporal to ChronoZonedDateTimeImpl ensuring it bas the specified chronology.

Parameters
chrono:Chronology

the chronology to check for, not null

temporal:Temporal

a date-time to cast, not null

Returns:ChronoZonedDateTimeImpl<R>

the date-time checked and cast to ChronoZonedDateTimeImpl, not null

Exceptions
ClassCastException:
if the date-time cannot be cast to ChronoZonedDateTimeImpl or the chronology is not equal this Chronology
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.time.chrono.ChronoZonedDateTime.equals.

Doc from java.time.chrono.ChronoZonedDateTime.equals.

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 compareTo. Only objects of type ChronoZonedDateTime are compared, other types return false.

Parameters
obj:Object

the object to check, null returns false

Returns:boolean

true if this is equal to the other date-time

Annotations
@Override
getOffsetback to summary
public ZoneOffset getOffset()

Implements java.time.chrono.ChronoZonedDateTime.getOffset.

Doc from java.time.chrono.ChronoZonedDateTime.getOffset.

Gets the zone offset, such as '+01:00'.

This is the offset of the local date-time from UTC/Greenwich.

Returns:ZoneOffset

the zone offset, not null

Annotations
@Override
getZoneback to summary
public ZoneId getZone()

Implements java.time.chrono.ChronoZonedDateTime.getZone.

Doc from java.time.chrono.ChronoZonedDateTime.getZone.

Gets the zone ID, such as 'Europe/Paris'.

This returns the stored time-zone id used to determine the time-zone rules.

Returns:ZoneId

the zone ID, not null

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.time.chrono.ChronoZonedDateTime.hashCode.

Doc from java.time.chrono.ChronoZonedDateTime.hashCode.

A hash code for this date-time.

Returns:int

a suitable hash code

Annotations
@Override
isSupportedback to summary
public boolean isSupported(TemporalField field)

Implements java.time.chrono.ChronoZonedDateTime.isSupported.

Doc from java.time.chrono.ChronoZonedDateTime.isSupported.

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 range, get and with(TemporalField, long) methods will throw an exception.

The set of supported fields is defined by the chronology and normally includes all ChronoField fields.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.isSupportedBy(TemporalAccessor) passing this as the argument. Whether the field is supported is determined by the field.

Parameters
field:TemporalField

the field to check, null returns false

Returns:boolean

true if the field can be queried, false if not

Annotations
@Override
ofBestback to summary
pack-priv static <R extends ChronoLocalDate> ChronoZonedDateTime<R> ofBest(ChronoLocalDateTimeImpl<R> localDateTime, ZoneId zone, ZoneOffset preferredOffset)

Obtains an instance from a local date-time using the preferred offset if possible.

Parameters
localDateTime:ChronoLocalDateTimeImpl<R>

the local date-time, not null

zone:ZoneId

the zone identifier, not null

preferredOffset:ZoneOffset

the zone offset, null if no preference

Returns:ChronoZonedDateTime<R>

the zoned date-time, not null

ofInstantback to summary
pack-priv static ChronoZonedDateTimeImpl<?> ofInstant(Chronology chrono, Instant instant, ZoneId zone)

Obtains an instance from an instant using the specified time-zone.

Parameters
chrono:Chronology

the chronology, not null

instant:Instant

the instant, not null

zone:ZoneId

the zone identifier, not null

Returns:ChronoZonedDateTimeImpl<?>

the zoned date-time, not null

plusback to summary
public ChronoZonedDateTime<D> plus(long amountToAdd, TemporalUnit unit)

Implements java.time.chrono.ChronoZonedDateTime.plus.

Doc from java.time.chrono.ChronoZonedDateTime.plus.

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 LocalDate, this could be used to add a number of years, months or days. The returned object will have the same observable type as this object.

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.

Parameters
amountToAdd:long

Doc from java.time.temporal.Temporal.plus.

the amount of the specified unit to add, may be negative

unit:TemporalUnit

Doc from java.time.temporal.Temporal.plus.

the unit of the amount to add, not null

Returns:ChronoZonedDateTime<D>

Doc from java.time.temporal.Temporal.plus.

an object of the same type with the specified period added, not null

Annotations
@Override
readExternalback to summary
pack-priv static ChronoZonedDateTime<?> readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readObjectback to summary
private void readObject(ObjectInputStream s) throws InvalidObjectException

Defend against malicious streams.

Parameters
s:ObjectInputStream

the stream to read

Annotations
@Serial
Exceptions
InvalidObjectException:
always
toLocalDateTimeback to summary
public ChronoLocalDateTime<D> toLocalDateTime()

Implements java.time.chrono.ChronoZonedDateTime.toLocalDateTime.

Doc from java.time.chrono.ChronoZonedDateTime.toLocalDateTime.

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.

Returns:ChronoLocalDateTime<D>

the local date-time part of this date-time, not null

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.time.chrono.ChronoZonedDateTime.toString.

Doc from java.time.chrono.ChronoZonedDateTime.toString.

Outputs this date-time as a String.

The output will include the full zoned date-time.

Returns:String

a string representation of this date-time, not null

Annotations
@Override
untilback to summary
public long until(Temporal endExclusive, TemporalUnit unit)

Implements java.time.temporal.Temporal.until.

Doc from java.time.temporal.Temporal.until.

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 TemporalUnit. The start and end points are this and the specified temporal. The end point is converted to be of the same type as the start point if different. The result will be negative if the end is before the start. For example, the amount in hours between two temporal objects can be calculated using startTime.until(endTime, HOURS).

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 TemporalUnit#between(Temporal, Temporal):

  // 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);
Parameters
endExclusive:Temporal

the end temporal, exclusive, converted to be of the same type as this object, not null

unit:TemporalUnit

the unit to measure the amount in, not null

Returns:long

the amount of time between this temporal object and the specified one in terms of the unit; positive if the specified object is later than this one, negative if it is earlier than this one

Annotations
@Override
withback to summary
public ChronoZonedDateTime<D> with(TemporalField field, long newValue)

Implements java.time.chrono.ChronoZonedDateTime.with.

Doc from java.time.chrono.ChronoZonedDateTime.with.

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 LocalDate, this could be used to set the year, month or day-of-month. The returned object will have the same observable type as this object.

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.

Parameters
field:TemporalField

Doc from java.time.temporal.Temporal.with.

the field to set in the result, not null

newValue:long

Doc from java.time.temporal.Temporal.with.

the new value of the field in the result

Returns:ChronoZonedDateTime<D>

Doc from java.time.temporal.Temporal.with.

an object of the same type with the specified field set, not null

Annotations
@Override
withEarlierOffsetAtOverlapback to summary
public ChronoZonedDateTime<D> withEarlierOffsetAtOverlap()

Implements java.time.chrono.ChronoZonedDateTime.withEarlierOffsetAtOverlap.

Doc from java.time.chrono.ChronoZonedDateTime.withEarlierOffsetAtOverlap.

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 is returned.

This instance is immutable and unaffected by this method call.

Returns:ChronoZonedDateTime<D>

a ChronoZonedDateTime based on this date-time with the earlier offset, not null

Annotations
@Override
withLaterOffsetAtOverlapback to summary
public ChronoZonedDateTime<D> withLaterOffsetAtOverlap()

Implements java.time.chrono.ChronoZonedDateTime.withLaterOffsetAtOverlap.

Doc from java.time.chrono.ChronoZonedDateTime.withLaterOffsetAtOverlap.

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 is returned.

This instance is immutable and unaffected by this method call.

Returns:ChronoZonedDateTime<D>

a ChronoZonedDateTime based on this date-time with the later offset, not null

Annotations
@Override
withZoneSameInstantback to summary
public ChronoZonedDateTime<D> withZoneSameInstant(ZoneId zone)

Implements java.time.chrono.ChronoZonedDateTime.withZoneSameInstant.

Doc from java.time.chrono.ChronoZonedDateTime.withZoneSameInstant.

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(ZoneId).

Parameters
zone:ZoneId

the time-zone to change to, not null

Returns:ChronoZonedDateTime<D>

a ChronoZonedDateTime based on this date-time with the requested zone, not null

Annotations
@Override
withZoneSameLocalback to summary
public ChronoZonedDateTime<D> withZoneSameLocal(ZoneId zone)

Implements java.time.chrono.ChronoZonedDateTime.withZoneSameLocal.

Doc from java.time.chrono.ChronoZonedDateTime.withZoneSameLocal.

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 withZoneSameInstant(ZoneId).

This instance is immutable and unaffected by this method call.

Parameters
zone:ZoneId

the time-zone to change to, not null

Returns:ChronoZonedDateTime<D>

a ChronoZonedDateTime based on this date-time with the requested zone, not null

Annotations
@Override
writeExternalback to summary
pack-priv void writeExternal(ObjectOutput out) throws IOException
writeReplaceback to summary
private Object writeReplace()

Writes the ChronoZonedDateTime using a dedicated serialized form.

Returns:Object

the instance of Ser, not null

Annotations
@Serial
Serial data
 out.writeByte(3);                  // identifies a ChronoZonedDateTime
 out.writeObject(toLocalDateTime());
 out.writeObject(getOffset());
 out.writeObject(getZone());