ChronoLocalDateTime is an immutable date-time object that represents a date-time, often
viewed as year-month-day-hour-minute-second. This object can also access other
fields such as day-of-year, day-of-week and week-of-year.
This class stores all date and time fields, to a precision of nanoseconds.
It does not store or represent a time-zone. For example, the value
"2nd October 2007 at 13:45.30.123456789" can be stored in an ChronoLocalDateTime.
Implementation Specification
This class is immutable and thread-safe.
| Modifier and Type | Field and Description |
|---|---|
| private final transient D | date
The date part. |
| pack-priv static final int | HOURS_PER_DAY
Hours per day. |
| pack-priv static final long | MICROS_PER_DAY
Microseconds per day. |
| pack-priv static final long | MILLIS_PER_DAY
Milliseconds per day. |
| pack-priv static final int | MINUTES_PER_DAY
Minutes per day. |
| pack-priv static final int | MINUTES_PER_HOUR
Minutes per hour. |
| pack-priv static final long | NANOS_PER_DAY
Nanos per day. |
| pack-priv static final long | NANOS_PER_HOUR
Nanos per hour. |
| pack-priv static final long | NANOS_PER_MINUTE
Nanos per minute. |
| pack-priv static final long | NANOS_PER_SECOND
Nanos per second. |
| pack-priv static final int | SECONDS_PER_DAY
Seconds per day. |
| pack-priv static final int | SECONDS_PER_HOUR
Seconds per hour. |
| pack-priv static final int | SECONDS_PER_MINUTE
Seconds per minute. |
| private static final long | serialVersionUID
Serialization version. |
| private final transient LocalTime | time
The time part. |
| Access | Constructor and Description |
|---|---|
| private | ChronoLocalDateTimeImpl(D
the date part of the date-time, not null date, LocalTime the time part of the date-time, not null time)Constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public ChronoZonedDateTime | atZone(ZoneId zone)
Implements java. Combines this time with a time-zone to create a |
| pack-priv static <R extends ChronoLocalDate> ChronoLocalDateTimeImpl | Returns: the date-time checked and cast toChronoLocalDateTime, not nullthe chronology to check for, not null chrono, Temporal a date-time to cast, not null temporal)Casts the |
| public boolean | equals(Object obj)
Overrides java. Implements java. Checks if this date-time is equal to another date-time, including the chronology. |
| public int | get(TemporalField field)
Overrides default java. Gets the value of the specified field as an |
| public long | getLong(TemporalField field)
Implements java. Gets the value of the specified field as a |
| public int | hashCode()
Overrides java. Implements java. A hash code for this date-time. |
| public boolean | isSupported(TemporalField field)
Implements java. Checks if the specified field is supported. |
| pack-priv static <R extends ChronoLocalDate> ChronoLocalDateTimeImpl | |
| public ChronoLocalDateTimeImpl | plus(long amountToAdd, TemporalUnit unit)
Implements java. Returns an object of the same type as this object with the specified period added. |
| private ChronoLocalDateTimeImpl | |
| private ChronoLocalDateTimeImpl | |
| private ChronoLocalDateTimeImpl | |
| private ChronoLocalDateTimeImpl | |
| pack-priv ChronoLocalDateTimeImpl | |
| private ChronoLocalDateTimeImpl | |
| public ValueRange | range(TemporalField field)
Overrides default java. Gets the range of valid values for the specified field. |
| pack-priv static ChronoLocalDateTime | |
| private void | |
| public D | toLocalDate()
Implements java. Gets the local date part of this date-time. |
| public LocalTime | toLocalTime()
Implements java. Gets the local time part of this date-time. |
| public String | toString()
Overrides java. Implements java. Outputs this date-time as a |
| public long | until(Temporal endExclusive, TemporalUnit unit)
Implements java. Calculates the amount of time until another temporal in terms of the specified unit. |
| private ChronoLocalDateTimeImpl | |
| public ChronoLocalDateTimeImpl | with(TemporalAdjuster adjuster)
Overrides default java. Returns an adjusted object of the same type as this object with the adjustment made. |
| public ChronoLocalDateTimeImpl | with(TemporalField field, long newValue)
Implements java. Returns an object of the same type as this object with the specified field altered. |
| pack-priv void | |
| private Object | Returns: the instance ofSer, not nullWrites the ChronoLocalDateTime using a dedicated serialized form. |
| date | back to summary |
|---|---|
| private final transient D date The date part. | |
| HOURS_PER_DAY | back to summary |
|---|---|
| pack-priv static final int HOURS_PER_DAY Hours per day. | |
| MICROS_PER_DAY | back to summary |
|---|---|
| pack-priv static final long MICROS_PER_DAY Microseconds per day. | |
| MILLIS_PER_DAY | back to summary |
|---|---|
| pack-priv static final long MILLIS_PER_DAY Milliseconds per day. | |
| MINUTES_PER_DAY | back to summary |
|---|---|
| pack-priv static final int MINUTES_PER_DAY Minutes per day. | |
| MINUTES_PER_HOUR | back to summary |
|---|---|
| pack-priv static final int MINUTES_PER_HOUR Minutes per hour. | |
| NANOS_PER_DAY | back to summary |
|---|---|
| pack-priv static final long NANOS_PER_DAY Nanos per day. | |
| NANOS_PER_HOUR | back to summary |
|---|---|
| pack-priv static final long NANOS_PER_HOUR Nanos per hour. | |
| NANOS_PER_MINUTE | back to summary |
|---|---|
| pack-priv static final long NANOS_PER_MINUTE Nanos per minute. | |
| NANOS_PER_SECOND | back to summary |
|---|---|
| pack-priv static final long NANOS_PER_SECOND Nanos per second. | |
| SECONDS_PER_DAY | back to summary |
|---|---|
| pack-priv static final int SECONDS_PER_DAY Seconds per day. | |
| SECONDS_PER_HOUR | back to summary |
|---|---|
| pack-priv static final int SECONDS_PER_HOUR Seconds per hour. | |
| SECONDS_PER_MINUTE | back to summary |
|---|---|
| pack-priv static final int SECONDS_PER_MINUTE Seconds per minute. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version. | |
| time | back to summary |
|---|---|
| private final transient LocalTime time The time part. | |
| ChronoLocalDateTimeImpl | back to summary |
|---|---|
| private ChronoLocalDateTimeImpl(D date, LocalTime time) Constructor.
| |
| atZone | back to summary |
|---|---|
| public ChronoZonedDateTime Implements java. Doc from java. 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
| |
| ensureValid | back to summary |
|---|---|
| pack-priv static <R extends ChronoLocalDate> ChronoLocalDateTimeImpl 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, including the chronology. Compares this date-time with another ensuring that the date-time and chronology are the same.
| |
| get | back to summary |
|---|---|
| public 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.
| |
| getLong | back to summary |
|---|---|
| public 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.
| |
| 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
| |
| of | back to summary |
|---|---|
| pack-priv static <R extends ChronoLocalDate> ChronoLocalDateTimeImpl Obtains an instance of
| |
| plus | back to summary |
|---|---|
| public ChronoLocalDateTimeImpl 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.
| |
| plusDays | back to summary |
|---|---|
| private ChronoLocalDateTimeImpl | |
| plusHours | back to summary |
|---|---|
| private ChronoLocalDateTimeImpl | |
| plusMinutes | back to summary |
|---|---|
| private ChronoLocalDateTimeImpl | |
| plusNanos | back to summary |
|---|---|
| private ChronoLocalDateTimeImpl | |
| plusSeconds | back to summary |
|---|---|
| pack-priv ChronoLocalDateTimeImpl | |
| plusWithOverflow | back to summary |
|---|---|
| private ChronoLocalDateTimeImpl | |
| range | back to summary |
|---|---|
| public 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.
| |
| readExternal | back to summary |
|---|---|
| pack-priv static ChronoLocalDateTime | |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws InvalidObjectException Defend against malicious streams.
| |
| toLocalDate | back to summary |
|---|---|
| public D toLocalDate() Implements java. Doc from java. 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() Implements java. Doc from java. 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() Overrides java. Implements java. Doc from java. Outputs this date-time as a The output will include the full local 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 amount = start.until(end, unit); amount = 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 |
|---|---|
| private ChronoLocalDateTimeImpl Returns a copy of this date-time with the new date and time, checking to see if a new object is in fact required.
| |
| with | back to summary |
|---|---|
| public ChronoLocalDateTimeImpl 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 ChronoLocalDateTimeImpl 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.
| |
| writeExternal | back to summary |
|---|---|
| pack-priv void writeExternal(ObjectOutput out) throws IOException | |
| writeReplace | back to summary |
|---|---|
| private Object writeReplace() Writes the ChronoLocalDateTime using a dedicated serialized form. | |