C - the chronology of this date-timepublic abstract class DefaultInterfaceChronoLocalDateTime<C extends Chrono<C>> extends DefaultInterfaceTemporal implements ChronoLocalDateTime<C>
DATE_TIME_COMPARATOR| Constructor and Description |
|---|
DefaultInterfaceChronoLocalDateTime() |
| Modifier and Type | Method and Description |
|---|---|
Temporal |
adjustInto(Temporal temporal)
Adjusts the specified temporal object.
|
int |
compareTo(ChronoLocalDateTime<?> other)
Compares this date-time to another date-time, including the chronology.
|
boolean |
equals(Object obj)
Checks if this date-time is equal to another date-time, including the chronology.
|
int |
hashCode()
A hash code for this date-time.
|
boolean |
isAfter(ChronoLocalDateTime<?> other)
Checks if this date-time is after the specified date-time ignoring the chronology.
|
boolean |
isBefore(ChronoLocalDateTime<?> other)
Checks if this date-time is before the specified date-time ignoring the chronology.
|
boolean |
isEqual(ChronoLocalDateTime<?> other)
Checks if this date-time is equal to the specified date-time ignoring the chronology.
|
ChronoLocalDateTime<C> |
minus(long amountToSubtract,
TemporalUnit unit)
Returns an object of the same type as this object with the specified period subtracted.
|
ChronoLocalDateTime<C> |
minus(TemporalSubtractor adjuster)
Returns an object of the same type as this object with an amount subtracted.
|
ChronoLocalDateTime<C> |
plus(TemporalAdder adjuster)
Returns an object of the same type as this object with an amount added.
|
<R> R |
query(TemporalQuery<R> query)
Queries this date-time.
|
long |
toEpochSecond(ZoneOffset offset)
Converts this date-time to the number of seconds from the epoch
of 1970-01-01T00:00:00Z.
|
Instant |
toInstant(ZoneOffset offset)
Converts this date-time to an
Instant. |
String |
toString()
Outputs this date-time as a
String. |
String |
toString(DateTimeFormatter formatter)
Outputs this date-time as a
String using the formatter. |
ChronoLocalDateTime<C> |
with(TemporalAdjuster adjuster)
Returns an adjusted object of the same type as this object with the adjustment made.
|
get, rangeclone, finalize, getClass, notify, notifyAll, wait, wait, waitatZone, getDate, getTime, plus, withperiodUntilget, getLong, isSupported, rangepublic DefaultInterfaceChronoLocalDateTime()
public ChronoLocalDateTime<C> with(TemporalAdjuster adjuster)
Temporal
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 TemporalAdjusters date = date.with(next(WEDNESDAY)); // static import from TemporalAdjusters and DayOfWeek
with in interface ChronoLocalDateTime<C extends Chrono<C>>with in interface Temporalwith in class DefaultInterfaceTemporaladjuster - the adjuster to use, not nullpublic ChronoLocalDateTime<C> plus(TemporalAdder adjuster)
Temporal
This adjusts this temporal, adding according to the rules of the specified adder.
The adder is typically a Period but may be any other type implementing
the TemporalAdder interface, such as Duration.
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(MONTHS.between(start, end)); // static import of MONTHS field date = date.plus(workingDays(6)); // example user-written workingDays method
Note that calling plus followed by minus is not guaranteed to
return the same date-time.
plus in interface ChronoLocalDateTime<C extends Chrono<C>>plus in interface Temporalplus in class DefaultInterfaceTemporaladjuster - the adder to use, not nullpublic ChronoLocalDateTime<C> minus(TemporalSubtractor adjuster)
Temporal
This adjusts this temporal, subtracting according to the rules of the specified subtractor.
The subtractor is typically a Period but may be any other type implementing
the TemporalSubtractor interface, such as Duration.
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(MONTHS.between(start, end)); // static import of MONTHS field date = date.minus(workingDays(6)); // example user-written workingDays method
Note that calling plus followed by minus is not guaranteed to
return the same date-time.
minus in interface ChronoLocalDateTime<C extends Chrono<C>>minus in interface Temporalminus in class DefaultInterfaceTemporaladjuster - the subtractor to use, not nullpublic ChronoLocalDateTime<C> minus(long amountToSubtract, TemporalUnit unit)
Temporal
This method returns a new object based on this one with the specified period subtracted.
For example, on a LocalDate, this could be used to subtract 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 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.
If the implementation represents a date-time that has boundaries, such as LocalTime,
then the permitted units must include the boundary unit, but no multiples of the boundary unit.
For example, LocalTime must accept DAYS but not WEEKS or MONTHS.
Implementations must not alter either this object or the specified temporal object. Instead, an adjusted copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable implementations.
minus in interface ChronoLocalDateTime<C extends Chrono<C>>minus in interface Temporalminus in class DefaultInterfaceTemporalamountToSubtract - the amount of the specified unit to subtract, may be negativeunit - the unit of the period to subtract, not nullpublic Temporal adjustInto(Temporal temporal)
TemporalAdjusterThis adjusts the specified temporal object using the logic encapsulated in the implementing class. Examples might be an adjuster that sets the date avoiding weekends, or one that sets the date to the last day of the month.
There are two equivalent ways of using this method.
The first is to invoke this method directly.
The second is to use Temporal.with(TemporalAdjuster):
// these two lines are equivalent, but the second approach is recommended temporal = thisAdjuster.adjustInto(temporal); temporal = temporal.with(thisAdjuster);It is recommended to use the second approach,
with(TemporalAdjuster),
as it is a lot clearer to read in code.
Temporal to
query the temporal object and perform the adjustment.
The returned object must have the same observable type as the input object
The input object must not be altered. Instead, an adjusted copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable temporal objects.
The input temporal object may be in a calendar system other than ISO.
Implementations may choose to document compatibility with other calendar systems,
or reject non-ISO temporal objects by querying the chronology.
This method may be called from multiple threads in parallel. It must be thread-safe when invoked.
adjustInto in interface TemporalAdjustertemporal - the temporal object to adjust, not nullpublic <R> R query(TemporalQuery<R> query)
TemporalAccessorThis queries this date-time using the specified query strategy object.
Queries are a key tool for extracting information from date-times. They exists to externalize the process of querying, permitting different approaches, as per the strategy design pattern. Examples might be a query that checks if the date is the day before February 29th in a leap year, or calculates the number of days to your next birthday.
The most common query implementations are method references, such as
LocalDate::from and ZoneId::from.
Further implementations are on TemporalQueries.
Queries may also be defined by applications.
public <R> R query(TemporalQuery<R> type) {
// only include an if statement if the implementation can return it
if (query == TemporalQueries.zoneId()) return // the ZoneId
if (query == TemporalQueries.chrono()) return // the Chrono
if (query == TemporalQueries.precision()) return // the precision
// call default method
return super.query(query);
}
query in interface TemporalAccessorquery in class DefaultInterfaceTemporalAccessorR - the type of the resultquery - the query to invoke, not nullpublic Instant toInstant(ZoneOffset offset)
ChronoLocalDateTimeInstant.
This combines this local date-time and the specified offset to form
an Instant.
toInstant in interface ChronoLocalDateTime<C extends Chrono<C>>offset - the offset to use for the conversion, not nullInstant representing the same instant, not nullpublic long toEpochSecond(ZoneOffset offset)
ChronoLocalDateTimeThis 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.
toEpochSecond in interface ChronoLocalDateTime<C extends Chrono<C>>offset - the offset to use for the conversion, not nullpublic int compareTo(ChronoLocalDateTime<?> other)
ChronoLocalDateTime
The comparison is based first on the underlying time-line date-time, then
on the chronology.
It is "consistent with equals", as defined by Comparable.
For example, the following is the comparator order:
2012-12-03T12:00 (ISO)2012-12-04T12:00 (ISO)2555-12-04T12:00 (ThaiBuddhist)2012-12-05T12:00 (ISO)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.
compareTo in interface Comparable<ChronoLocalDateTime<?>>compareTo in interface ChronoLocalDateTime<C extends Chrono<C>>other - the other date-time to compare to, not nullpublic boolean isAfter(ChronoLocalDateTime<?> other)
ChronoLocalDateTime
This method differs from the comparison in ChronoLocalDateTime.compareTo(org.threeten.bp.temporal.ChronoLocalDateTime<?>) in that it
only compares the underlying date-time and not the chronology.
This allows dates in different calendar systems to be compared based
on the time-line position.
isAfter in interface ChronoLocalDateTime<C extends Chrono<C>>other - the other date-time to compare to, not nullpublic boolean isBefore(ChronoLocalDateTime<?> other)
ChronoLocalDateTime
This method differs from the comparison in ChronoLocalDateTime.compareTo(org.threeten.bp.temporal.ChronoLocalDateTime<?>) in that it
only compares the underlying date-time and not the chronology.
This allows dates in different calendar systems to be compared based
on the time-line position.
isBefore in interface ChronoLocalDateTime<C extends Chrono<C>>other - the other date-time to compare to, not nullpublic boolean isEqual(ChronoLocalDateTime<?> other)
ChronoLocalDateTime
This method differs from the comparison in ChronoLocalDateTime.compareTo(org.threeten.bp.temporal.ChronoLocalDateTime<?>) in that it
only compares the underlying date and time and not the chronology.
This allows date-times in different calendar systems to be compared based
on the time-line position.
isEqual in interface ChronoLocalDateTime<C extends Chrono<C>>other - the other date-time to compare to, not nullpublic boolean equals(Object obj)
ChronoLocalDateTimeCompares this date-time with another ensuring that the date-time and chronology are the same.
public int hashCode()
ChronoLocalDateTimepublic String toString()
ChronoLocalDateTimeString.
The output will include the full local date-time and the chronology ID.
public String toString(DateTimeFormatter formatter)
ChronoLocalDateTimeString using the formatter.toString in interface ChronoLocalDateTime<C extends Chrono<C>>formatter - the formatter to use, not nullCopyright © 2007-2013 ThreeTen.org. All Rights Reserved.