APIdia Launch Partner
Top Description Fields Constructors Methods
java.time.chrono

pack-priv final Class ChronoLocalDateTimeImpl<D extends ChronoLocalDate>

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

A date-time without a time-zone for the calendar neutral API.

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.

Since
1.8

Field Summary

Modifier and TypeField 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.

Constructor Summary

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

Method Summary

Modifier and TypeMethod and Description
public ChronoZonedDateTime<D>
atZone(ZoneId zone)

Implements java.time.chrono.ChronoLocalDateTime.atZone.

Combines this time with a time-zone to create a ChronoZonedDateTime.

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

Returns:

the date-time checked and cast to ChronoLocalDateTime, 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 ChronoLocalDateTime ensuring it bas the specified chronology.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.time.chrono.ChronoLocalDateTime.equals.

Checks if this date-time is equal to another date-time, including the chronology.

public int
get(TemporalField field)

Overrides default java.time.temporal.TemporalAccessor.get.

Gets the value of the specified field as an int.

public long
getLong(TemporalField field)

Implements java.time.temporal.TemporalAccessor.getLong.

Gets the value of the specified field as a long.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.time.chrono.ChronoLocalDateTime.hashCode.

A hash code for this date-time.

public boolean
pack-priv static <R extends ChronoLocalDate> ChronoLocalDateTimeImpl<R>

Returns:

the local date-time, not null
of
(R
the local date, not null
date
,
LocalTime
the local time, not null
time
)

Obtains an instance of ChronoLocalDateTime from a date and time.

public ChronoLocalDateTimeImpl<D>
plus(long amountToAdd, TemporalUnit unit)

Implements java.time.chrono.ChronoLocalDateTime.plus, java.time.temporal.Temporal.plus.

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

private ChronoLocalDateTimeImpl<D>
plusDays(long days)

private ChronoLocalDateTimeImpl<D>
plusHours(long hours)

private ChronoLocalDateTimeImpl<D>
plusMinutes(long minutes)

private ChronoLocalDateTimeImpl<D>
plusNanos(long nanos)

pack-priv ChronoLocalDateTimeImpl<D>
plusSeconds(long seconds)

private ChronoLocalDateTimeImpl<D>
plusWithOverflow(D newDate, long hours, long minutes, long seconds, long nanos)

public ValueRange
range(TemporalField field)

Overrides default java.time.temporal.TemporalAccessor.range.

Gets the range of valid values for the specified field.

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

Defend against malicious streams.

public D
toLocalDate()

Implements java.time.chrono.ChronoLocalDateTime.toLocalDate.

Gets the local date part of this date-time.

public LocalTime
toLocalTime()

Implements java.time.chrono.ChronoLocalDateTime.toLocalTime.

Gets the local time part of this date-time.

public String
toString()

Overrides java.lang.Object.toString.

Implements java.time.chrono.ChronoLocalDateTime.toString.

Outputs this date-time as a String.

public long
until(Temporal endExclusive, TemporalUnit unit)

Implements java.time.temporal.Temporal.until.

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

private ChronoLocalDateTimeImpl<D>

Returns:

the date-time, not null
with
(Temporal
the date of the new date-time, not null
newDate
,
LocalTime
the time of the new date-time, not null
newTime
)

Returns a copy of this date-time with the new date and time, checking to see if a new object is in fact required.

public ChronoLocalDateTimeImpl<D>
with(TemporalAdjuster adjuster)

Overrides default java.time.chrono.ChronoLocalDateTime.with, java.time.temporal.Temporal.with.

Returns an adjusted object of the same type as this object with the adjustment made.

public ChronoLocalDateTimeImpl<D>
with(TemporalField field, long newValue)

Implements java.time.chrono.ChronoLocalDateTime.with, java.time.temporal.Temporal.with.

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

pack-priv void
private Object

Returns:

the instance of Ser, not null
writeReplace
()

Writes the ChronoLocalDateTime using a dedicated serialized form.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

dateback to summary
private final transient D date

The date part.

HOURS_PER_DAYback to summary
pack-priv static final int HOURS_PER_DAY

Hours per day.

MICROS_PER_DAYback to summary
pack-priv static final long MICROS_PER_DAY

Microseconds per day.

MILLIS_PER_DAYback to summary
pack-priv static final long MILLIS_PER_DAY

Milliseconds per day.

MINUTES_PER_DAYback to summary
pack-priv static final int MINUTES_PER_DAY

Minutes per day.

MINUTES_PER_HOURback to summary
pack-priv static final int MINUTES_PER_HOUR

Minutes per hour.

NANOS_PER_DAYback to summary
pack-priv static final long NANOS_PER_DAY

Nanos per day.

NANOS_PER_HOURback to summary
pack-priv static final long NANOS_PER_HOUR

Nanos per hour.

NANOS_PER_MINUTEback to summary
pack-priv static final long NANOS_PER_MINUTE

Nanos per minute.

NANOS_PER_SECONDback to summary
pack-priv static final long NANOS_PER_SECOND

Nanos per second.

SECONDS_PER_DAYback to summary
pack-priv static final int SECONDS_PER_DAY

Seconds per day.

SECONDS_PER_HOURback to summary
pack-priv static final int SECONDS_PER_HOUR

Seconds per hour.

SECONDS_PER_MINUTEback to summary
pack-priv static final int SECONDS_PER_MINUTE

Seconds per minute.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

Annotations
@Serial
timeback to summary
private final transient LocalTime time

The time part.

Constructor Detail

ChronoLocalDateTimeImplback to summary
private ChronoLocalDateTimeImpl(D date, LocalTime time)

Constructor.

Parameters
date:D

the date part of the date-time, not null

time:LocalTime

the time part of the date-time, not null

Method Detail

atZoneback to summary
public ChronoZonedDateTime<D> atZone(ZoneId zone)

Implements java.time.chrono.ChronoLocalDateTime.atZone.

Doc from java.time.chrono.ChronoLocalDateTime.atZone.

Combines this time with a time-zone to create a ChronoZonedDateTime.

This returns a ChronoZonedDateTime formed from this date-time at the specified time-zone. The result will match this date-time as closely as possible. Time-zone rules, such as daylight savings, mean that not every local date-time is valid for the specified zone, thus the local date-time may be adjusted.

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 rules of the zone ID.

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 ChronoZonedDateTime#withLaterOffsetAtOverlap() on the result of this method.

Annotations
@Override
ensureValidback to summary
pack-priv static <R extends ChronoLocalDate> ChronoLocalDateTimeImpl<R> ensureValid(Chronology chrono, Temporal temporal)

Casts the Temporal to ChronoLocalDateTime 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:ChronoLocalDateTimeImpl<R>

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

Exceptions
ClassCastException:
if the date-time cannot be cast to ChronoLocalDateTimeImpl 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.ChronoLocalDateTime.equals.

Doc from java.time.chrono.ChronoLocalDateTime.equals.

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.

Annotations
@Override
getback to summary
public int get(TemporalField field)

Overrides default java.time.temporal.TemporalAccessor.get.

Doc from java.time.temporal.TemporalAccessor.get.

Gets the value of the specified field as an int.

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.

Annotations
@Override
getLongback to summary
public long getLong(TemporalField field)

Implements java.time.temporal.TemporalAccessor.getLong.

Doc from java.time.temporal.TemporalAccessor.getLong.

Gets the value of the specified field as a long.

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.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.time.chrono.ChronoLocalDateTime.hashCode.

Doc from java.time.chrono.ChronoLocalDateTime.hashCode.

A hash code for this date-time.

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

Implements java.time.chrono.ChronoLocalDateTime.isSupported, java.time.temporal.TemporalAccessor.isSupported.

Doc from java.time.chrono.ChronoLocalDateTime.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 date and time 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.

Annotations
@Override
ofback to summary
pack-priv static <R extends ChronoLocalDate> ChronoLocalDateTimeImpl<R> of(R date, LocalTime time)

Obtains an instance of ChronoLocalDateTime from a date and time.

Parameters
date:R

the local date, not null

time:LocalTime

the local time, not null

Returns:ChronoLocalDateTimeImpl<R>

the local date-time, not null

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

Implements java.time.chrono.ChronoLocalDateTime.plus, java.time.temporal.Temporal.plus.

Doc from java.time.chrono.ChronoLocalDateTime.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.

Annotations
@Override
plusDaysback to summary
private ChronoLocalDateTimeImpl<D> plusDays(long days)
plusHoursback to summary
private ChronoLocalDateTimeImpl<D> plusHours(long hours)
plusMinutesback to summary
private ChronoLocalDateTimeImpl<D> plusMinutes(long minutes)
plusNanosback to summary
private ChronoLocalDateTimeImpl<D> plusNanos(long nanos)
plusSecondsback to summary
pack-priv ChronoLocalDateTimeImpl<D> plusSeconds(long seconds)
plusWithOverflowback to summary
private ChronoLocalDateTimeImpl<D> plusWithOverflow(D newDate, long hours, long minutes, long seconds, long nanos)
rangeback to summary
public ValueRange range(TemporalField field)

Overrides default java.time.temporal.TemporalAccessor.range.

Doc from java.time.temporal.TemporalAccessor.range.

Gets the range of valid values for the specified field.

All fields can be expressed as a long integer. This method returns an object that describes the valid range for that value. The value of this temporal object is used to enhance the accuracy of the returned range. If the date-time cannot return the range, because the field is unsupported or for some other reason, an exception will be thrown.

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.

Annotations
@Override
readExternalback to summary
pack-priv static ChronoLocalDateTime<?> 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
toLocalDateback to summary
public D toLocalDate()

Implements java.time.chrono.ChronoLocalDateTime.toLocalDate.

Doc from java.time.chrono.ChronoLocalDateTime.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.

Annotations
@Override
toLocalTimeback to summary
public LocalTime toLocalTime()

Implements java.time.chrono.ChronoLocalDateTime.toLocalTime.

Doc from java.time.chrono.ChronoLocalDateTime.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.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.time.chrono.ChronoLocalDateTime.toString.

Doc from java.time.chrono.ChronoLocalDateTime.toString.

Outputs this date-time as a String.

The output will include the full local date-time.

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
  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);
Annotations
@Override
withback to summary
private ChronoLocalDateTimeImpl<D> with(Temporal newDate, LocalTime newTime)

Returns a copy of this date-time with the new date and time, checking to see if a new object is in fact required.

Parameters
newDate:Temporal

the date of the new date-time, not null

newTime:LocalTime

the time of the new date-time, not null

Returns:ChronoLocalDateTimeImpl<D>

the date-time, not null

withback to summary
public ChronoLocalDateTimeImpl<D> with(TemporalAdjuster adjuster)

Overrides default java.time.chrono.ChronoLocalDateTime.with, java.time.temporal.Temporal.with.

Doc from java.time.chrono.ChronoLocalDateTime.with.

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 TemporalAdjusters. These include finding the "last day of the month" and "next Wednesday". The adjuster is responsible for handling special cases, such as the varying lengths of month and leap years.

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
Annotations
@Override
withback to summary
public ChronoLocalDateTimeImpl<D> with(TemporalField field, long newValue)

Implements java.time.chrono.ChronoLocalDateTime.with, java.time.temporal.Temporal.with.

Doc from java.time.chrono.ChronoLocalDateTime.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.

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

Writes the ChronoLocalDateTime using a dedicated serialized form.

Returns:Object

the instance of Ser, not null

Annotations
@Serial
Serial data
 out.writeByte(2);              // identifies a ChronoLocalDateTime
 out.writeObject(toLocalDate());
 out.writeObject(toLocalTime());