Most applications should declare method signatures, fields and variables
as ZonedDateTime
, not this interface.
A ChronoZonedDateTime
is the abstract representation of an offset date-time
where the Chronology chronology
, or calendar system, is pluggable.
The date-time is defined in terms of fields expressed by TemporalField
,
where most common implementations are defined in ChronoField
.
The chronology defines how the calendar system operates and the meaning of
the standard fields.
ZonedDateTime
rather than this
interface, even in the case where the application needs to deal with multiple
calendar systems. The rationale for this is explored in detail in ChronoLocalDate
.
Ensure that the discussion in ChronoLocalDate
has been read and understood
before using this interface.
Implementation Specification
This interface must be implemented with care to ensure other classes operate correctly. All implementations that can be instantiated must be final, immutable and thread-safe. Subclasses should be Serializable wherever possible.
Modifier and Type | Method and Description |
---|---|
public default int | Returns: the comparator value, that is the comparison of this with theother values for the instant,
the local date-time, the zone ID, and the chronology, in order, returning the first non-zero result,
and otherwise returning zerothe other date-time to compare to, not null other)Implements java. Compares this date-time to another date-time, including the chronology. |
public boolean | |
public default String | Returns: the formatted date-time string, not nullthe formatter to use, not null formatter)Formats this date-time using the specified formatter. |
public static ChronoZonedDateTime | Returns: the date-time, not nullthe temporal object to convert, not null temporal)Obtains an instance of |
public default int | get(TemporalField
the field to get, not null field)Overrides default java. Gets the value of the specified field as an |
public default Chronology | |
public default long | getLong(TemporalField
the field to get, not null field)Implements java. Gets the value of the specified field as a |
public ZoneOffset | |
public ZoneId | |
public int | |
public default boolean | Returns: true if this is after the specified date-timethe other date-time to compare to, not null other)Checks if the instant of this date-time is after that of the specified date-time. |
public default boolean | Returns: true if this point is before the specified date-timethe other date-time to compare to, not null other)Checks if the instant of this date-time is before that of the specified date-time. |
public default boolean | Returns: true if the instant equals the instant of the specified date-timethe other date-time to compare to, not null other)Checks if the instant of this date-time is equal to that of the specified date-time. |
public boolean | Returns: true if the field can be queried, false if notthe field to check, null returns false field)Redeclares java. Checks if the specified field is supported. |
public default boolean | Returns: true if the unit can be added/subtracted, false if notthe unit to check, null returns false unit)Implements java. Checks if the specified unit is supported. |
public default ChronoZonedDateTime | minus(TemporalAmount
the amount to subtract, not null amount)Overrides default java. Returns an object of the same type as this object with an amount subtracted. |
public default ChronoZonedDateTime | minus(long
the amount of the specified unit to subtract, may be negative amountToSubtract, TemporalUnit the unit of the amount to subtract, not null unit)Overrides default java. Returns an object of the same type as this object with the specified period subtracted. |
public default ChronoZonedDateTime | plus(TemporalAmount
the amount to add, not null amount)Overrides default java. Returns an object of the same type as this object with an amount added. |
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)Redeclares java. Returns an object of the same type as this object with the specified period added. |
public default < the type of the result R> R | Returns: the query result, null may be returned (defined by the query)the query to invoke, not null query)Overrides default java. Queries this date-time using the specified query. |
public default ValueRange | range(TemporalField
the field to query the range for, not null field)Overrides default java. Gets the range of valid values for the specified field. |
public static Comparator | Returns: a comparator that compares in time-line order ignoring the chronologyGets a comparator that compares |
public default long | Returns: the number of seconds from the epoch of 1970-01-01T00:00:00ZConverts this date-time to the number of seconds from the epoch of 1970-01-01T00:00:00Z. |
public default Instant | Returns: anInstant representing the same instant, not nullConverts this date-time to an |
public default D | Returns: the date part of this date-time, not nullGets the local date part of this date-time. |
public ChronoLocalDateTime | Returns: the local date-time part of this date-time, not nullGets the local date-time part of this date-time. |
public default LocalTime | Returns: the time part of this date-time, not nullGets the local time part of this date-time. |
public String | Returns: a string representation of this date-time, not nullOutputs this date-time as a |
public default ChronoZonedDateTime | with(TemporalAdjuster
the adjuster to use, not null adjuster)Overrides default java. Returns an adjusted object of the same type as this object with the adjustment made. |
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)Redeclares java. Returns an object of the same type as this object with the specified field altered. |
public ChronoZonedDateTime | Returns: aChronoZonedDateTime based on this date-time with the earlier offset, not nullReturns 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 | Returns: aChronoZonedDateTime based on this date-time with the later offset, not nullReturns 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 | Returns: aChronoZonedDateTime based on this date-time with the requested zone, not nullthe time-zone to change to, not null zone)Returns a copy of this date-time with a different time-zone, retaining the instant. |
public ChronoZonedDateTime | Returns: aChronoZonedDateTime based on this date-time with the requested zone, not nullthe time-zone to change to, not null zone)Returns a copy of this date-time with a different time-zone, retaining the local date-time if possible. |
compareTo | back to summary |
---|---|
public default int compareTo(ChronoZonedDateTime<?> other) Implements java. Compares this date-time to another date-time, including the chronology.
The comparison is based first on the instant, then on the local date-time,
then on the zone ID, then on the chronology.
It is "consistent with equals", as defined by If all the date-time objects being compared are in the same chronology, then the additional chronology stage is not required. This default implementation performs the comparison defined above.
|
equals | back to summary |
---|---|
public boolean equals(Object obj) 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 |
format | back to summary |
---|---|
public default String format(DateTimeFormatter formatter) Formats this date-time using the specified formatter. This date-time will be passed to the formatter to produce a string. The default implementation must behave as follows: return formatter.format(this);
|
from | back to summary |
---|---|
public static ChronoZonedDateTime Obtains an instance of
This creates a zoned date-time based on the specified temporal.
A
The conversion extracts and combines the chronology, date, time and zone
from the temporal object. The behavior is equivalent to using
This method matches the signature of the functional interface
|
get | back to summary |
---|---|
public default int get(TemporalField field) Overrides default java. Doc from java. Gets the value of the specified field as an This queries the date-time for the value of the specified field. The returned value will always be within the valid range of values for the field. If the date-time cannot return the value, because the field is unsupported or for some other reason, an exception will be thrown.
|
getChronology | back to summary |
---|---|
public default Chronology getChronology() Gets the chronology of this date-time.
The
|
getLong | back to summary |
---|---|
public default long getLong(TemporalField field) Implements java. Doc from java. Gets the value of the specified field as a This queries the date-time for the value of the specified field. The returned value may be outside the valid range of values for the field. If the date-time cannot return the value, because the field is unsupported or for some other reason, an exception will be thrown.
|
getOffset | back to summary |
---|---|
public ZoneOffset getOffset() 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() 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() A hash code for this date-time.
|
isAfter | back to summary |
---|---|
public default boolean isAfter(ChronoZonedDateTime<?> other) Checks if the instant of this date-time is after that of the specified date-time.
This method differs from the comparison in This default implementation performs the comparison based on the epoch-second and nano-of-second.
|
isBefore | back to summary |
---|---|
public default boolean isBefore(ChronoZonedDateTime<?> other) Checks if the instant of this date-time is before that of the specified date-time.
This method differs from the comparison in This default implementation performs the comparison based on the epoch-second and nano-of-second.
|
isEqual | back to summary |
---|---|
public default boolean isEqual(ChronoZonedDateTime<?> other) Checks if the instant of this date-time is equal to that of the specified date-time.
This method differs from the comparison in This default implementation performs the comparison based on the epoch-second and nano-of-second.
|
isSupported | back to summary |
---|---|
public boolean isSupported(TemporalField field) Redeclares 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
|
isSupported | back to summary |
---|---|
public default boolean isSupported(TemporalUnit unit) Implements java. Checks if the specified unit is supported.
This checks if the specified unit can be added to or subtracted from this date-time.
If false, then calling the
The set of supported units is defined by the chronology and normally includes
all
If the unit is not a
|
minus | back to summary |
---|---|
public default ChronoZonedDateTime Overrides default java. Doc from java. Returns an object of the same type as this object with an amount subtracted.
This adjusts this temporal, subtracting according to the rules of the specified amount.
The amount is typically a Some example code indicating how and why this method is used: date = date.minus(period); // subtract a Period instance date = date.minus(duration); // subtract a Duration instance date = date.minus(workingDays(6)); // example user-written workingDays method
Note that calling
|
minus | back to summary |
---|---|
public default ChronoZonedDateTime Overrides default java. Doc from java. Returns an object of the same type as this object with the specified period subtracted.
This method returns a new object based on this one with the specified period subtracted.
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 March, then subtracting 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.
|
plus | back to summary |
---|---|
public default ChronoZonedDateTime Overrides default java. Doc from java. Returns an object of the same type as this object with an amount added.
This adjusts this temporal, adding according to the rules of the specified amount.
The amount is typically a Some example code indicating how and why this method is used: date = date.plus(period); // add a Period instance date = date.plus(duration); // add a Duration instance date = date.plus(workingDays(6)); // example user-written workingDays method
Note that calling
|
plus | back to summary |
---|---|
public ChronoZonedDateTime Redeclares 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.
|
query | back to summary |
---|---|
public default <R> R query(TemporalQuery<R> query) Overrides default java. Queries this date-time using the specified query.
This queries this date-time using the specified query strategy object.
The
The result of this method is obtained by invoking the
|
range | back to summary |
---|---|
public default ValueRange range(TemporalField field) Overrides default java. Doc from java. Gets the range of valid values for the specified field.
All fields can be expressed as a Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.
|
timeLineOrder | back to summary |
---|---|
public static Comparator Gets a comparator that compares
This comparator differs from the comparison in
|
toEpochSecond | back to summary |
---|---|
public default long toEpochSecond() Converts this date-time to the number of seconds from the epoch of 1970-01-01T00:00:00Z. This uses the local date-time and offset to calculate the epoch-second value, which is the number of elapsed seconds from 1970-01-01T00:00:00Z. Instants on the time-line after the epoch are positive, earlier are negative.
|
toInstant | back to summary |
---|---|
public default Instant toInstant() Converts this date-time to an
This returns an
|
toLocalDate | back to summary |
---|---|
public default D toLocalDate() Gets the local date part of this date-time. This returns a local date with the same year, month and day as this date-time.
|
toLocalDateTime | back to summary |
---|---|
public ChronoLocalDateTime 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.
|
toLocalTime | back to summary |
---|---|
public default LocalTime toLocalTime() Gets the local time part of this date-time. This returns a local time with the same hour, minute, second and nanosecond as this date-time.
|
toString | back to summary |
---|---|
public String toString() Outputs this date-time as a The output will include the full zoned date-time. |
with | back to summary |
---|---|
public default ChronoZonedDateTime Overrides default java. Doc from java. Returns an adjusted object of the same type as this object with the adjustment made.
This adjusts this date-time according to the rules of the specified adjuster.
A simple adjuster might simply set the one of the fields, such as the year field.
A more complex adjuster might set the date to the last day of the month.
A selection of common adjustments is provided in
Some example code indicating how and why this method is used: date = date.with(Month.JULY); // most key classes implement TemporalAdjuster date = date.with(lastDayOfMonth()); // static import from Adjusters date = date.with(next(WEDNESDAY)); // static import from Adjusters and DayOfWeek
|
with | back to summary |
---|---|
public ChronoZonedDateTime Redeclares 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 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 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 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 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.
|