Most applications should declare method signatures, fields and variables
as LocalDateTime
, not this interface.
A ChronoLocalDateTime
is the abstract representation of a local 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.
LocalDateTime
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 Temporal | Returns: the adjusted object, not nullthe target object to be adjusted, not null temporal)Implements java. Adjusts the specified temporal object to have the same date and time as this object. |
public ChronoZonedDateTime | |
public default int | Returns: the comparator value, that is the comparison of this local date-time with theother local date-time and this chronology with the other 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 ChronoLocalDateTime | Returns: the date-time, not nullthe temporal object to convert, not null temporal)Obtains an instance of |
public default Chronology | |
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 this date-time is after the specified date-time ignoring the chronology. |
public default boolean | Returns: true if this is before the specified date-timethe other date-time to compare to, not null other)Checks if this date-time is before the specified date-time ignoring the chronology. |
public default boolean | Returns: true if the underlying date-time is equal to the specified date-time on the timelinethe other date-time to compare to, not null other)Checks if this date-time is equal to the specified date-time ignoring the chronology. |
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 ChronoLocalDateTime | 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 ChronoLocalDateTime | 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 ChronoLocalDateTime | 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 ChronoLocalDateTime | 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 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:00Zthe offset to use for the conversion, not null offset)Converts 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 nullthe offset to use for the conversion, not null offset)Converts this date-time to an |
public D | Returns: the date part of this date-time, not nullGets the local date part of this date-time. |
public 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 ChronoLocalDateTime | 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 ChronoLocalDateTime | 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. |
adjustInto | back to summary |
---|---|
public default Temporal adjustInto(Temporal temporal) Implements java. Adjusts the specified temporal object to have the same date and time as this object. This returns a temporal object of the same observable type as the input with the date and time changed to be the same as this.
The adjustment is equivalent to using
In most cases, it is clearer to reverse the calling pattern by using
// these two lines are equivalent, but the second approach is recommended temporal = thisLocalDateTime.adjustInto(temporal); temporal = temporal.with(thisLocalDateTime); This instance is immutable and unaffected by this method call.
|
atZone | back to summary |
---|---|
public ChronoZonedDateTime Combines this time with a time-zone to create a
This returns a
The local date-time is resolved to a single instant on the time-line.
This is achieved by finding a valid offset from UTC/Greenwich for the local
date-time as defined by the In most cases, there is only one valid offset for a local date-time. In the case of an overlap, where clocks are set back, there are two valid offsets. This method uses the earlier offset typically corresponding to "summer". In the case of a gap, where clocks jump forward, there is no valid offset. Instead, the local date-time is adjusted to be later by the length of the gap. For a typical one hour daylight savings change, the local date-time will be moved one hour later into the offset typically corresponding to "summer".
To obtain the later offset during an overlap, call
|
compareTo | back to summary |
---|---|
public default int compareTo(ChronoLocalDateTime<?> other) Implements java. Compares this date-time to another date-time, including the chronology.
The comparison is based first on the underlying time-line date-time, then
on the chronology.
It is "consistent with equals", as defined by For example, the following is the comparator order:
If all the date-time objects being compared are in the same chronology, then the additional chronology stage is not required and only the local date-time is used. 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, including the chronology. Compares this date-time with another ensuring that the date-time and chronology are the same. |
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 ChronoLocalDateTime Obtains an instance of
This obtains a local date-time based on the specified temporal.
A
The conversion extracts and combines the chronology and the date-time
from the temporal object. The behavior is equivalent to using
This method matches the signature of the functional interface
|
getChronology | back to summary |
---|---|
public default Chronology getChronology() Gets the chronology of this date-time.
The
|
hashCode | back to summary |
---|---|
public int hashCode() A hash code for this date-time.
|
isAfter | back to summary |
---|---|
public default boolean isAfter(ChronoLocalDateTime<?> other) Checks if this date-time is after the specified date-time ignoring the chronology.
This method differs from the comparison in This default implementation performs the comparison based on the epoch-day and nano-of-day.
|
isBefore | back to summary |
---|---|
public default boolean isBefore(ChronoLocalDateTime<?> other) Checks if this date-time is before the specified date-time ignoring the chronology.
This method differs from the comparison in This default implementation performs the comparison based on the epoch-day and nano-of-day.
|
isEqual | back to summary |
---|---|
public default boolean isEqual(ChronoLocalDateTime<?> other) Checks if this date-time is equal to the specified date-time ignoring the chronology.
This method differs from the comparison in This default implementation performs the comparison based on the epoch-day and nano-of-day.
|
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 ChronoLocalDateTime 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 ChronoLocalDateTime 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 ChronoLocalDateTime 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 ChronoLocalDateTime 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
|
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(ZoneOffset offset) Converts this date-time to the number of seconds from the epoch of 1970-01-01T00:00:00Z. This combines this local date-time and the specified 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. This default implementation calculates from the epoch-day of the date and the second-of-day of the time.
|
toInstant | back to summary |
---|---|
public default Instant toInstant(ZoneOffset offset) Converts this date-time to an
This combines this local date-time and the specified offset to form
an This default implementation calculates from the epoch-day of the date and the second-of-day of the time.
|
toLocalDate | back to summary |
---|---|
public 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.
|
toLocalTime | back to summary |
---|---|
public 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 local date-time. |
with | back to summary |
---|---|
public default ChronoLocalDateTime 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 ChronoLocalDateTime 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.
|