C - the chronology of this date-timepublic abstract class DefaultInterfaceChronoZonedDateTime<C extends Chrono<C>> extends DefaultInterfaceTemporal implements ChronoZonedDateTime<C>
INSTANT_COMPARATOR| Constructor and Description |
|---|
DefaultInterfaceChronoZonedDateTime() |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(ChronoZonedDateTime<?> 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.
|
int |
get(TemporalField field)
Gets the value of the specified field as an
int. |
ChronoLocalDate<C> |
getDate()
Gets the local date part of this date-time.
|
long |
getLong(TemporalField field)
Gets the value of the specified field as a
long. |
LocalTime |
getTime()
Gets the local time part of this date-time.
|
int |
hashCode()
A hash code for this date-time.
|
boolean |
isAfter(ChronoZonedDateTime<?> other)
Checks if the instant of this date-time is after that of the specified date-time.
|
boolean |
isBefore(ChronoZonedDateTime<?> other)
Checks if the instant of this date-time is before that of the specified date-time.
|
boolean |
isEqual(ChronoZonedDateTime<?> other)
Checks if the instant of this date-time is equal to that of the specified date-time.
|
ChronoZonedDateTime<C> |
minus(long amountToSubtract,
TemporalUnit unit)
Returns an object of the same type as this object with the specified period subtracted.
|
ChronoZonedDateTime<C> |
minus(TemporalSubtractor adjuster)
Returns an object of the same type as this object with an amount subtracted.
|
ChronoZonedDateTime<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.
|
ValueRange |
range(TemporalField field)
Gets the range of valid values for the specified field.
|
long |
toEpochSecond()
Converts this date-time to the number of seconds from the epoch
of 1970-01-01T00:00:00Z.
|
Instant |
toInstant()
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. |
ChronoZonedDateTime<C> |
with(TemporalAdjuster adjuster)
Returns an adjusted object of the same type as this object with the adjustment made.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitgetDateTime, getOffset, getZone, plus, with, withEarlierOffsetAtOverlap, withLaterOffsetAtOverlap, withZoneSameInstant, withZoneSameLocalperiodUntilisSupportedpublic DefaultInterfaceChronoZonedDateTime()
public ValueRange range(TemporalField field)
TemporalAccessor
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.
ChronoField.
If the field is supported, then the range of the field must be returned.
If unsupported, then a DateTimeException must be thrown.
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.doRange(TemporalAccessorl)
passing this as the argument.
Implementations must not alter either this object.
range in interface TemporalAccessorrange in class DefaultInterfaceTemporalAccessorfield - the field to query the range for, not nullpublic int get(TemporalField field)
TemporalAccessorint.
This queries the date-time for the value for 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.
ChronoField.
If the field is supported and has an int range, then the value of
the field must be returned.
If unsupported, then a DateTimeException must be thrown.
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.doGet(TemporalAccessor)
passing this as the argument.
Implementations must not alter either this object.
get in interface TemporalAccessorget in class DefaultInterfaceTemporalAccessorfield - the field to get, not nullpublic long getLong(TemporalField field)
TemporalAccessorlong.
This queries the date-time for the value for 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.
ChronoField.
If the field is supported, then the value of the field must be returned.
If unsupported, then a DateTimeException must be thrown.
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.doGet(TemporalAccessor)
passing this as the argument.
Implementations must not alter either this object.
getLong in interface TemporalAccessorfield - the field to get, not nullpublic ChronoLocalDate<C> getDate()
ChronoZonedDateTimeThis returns a local date with the same year, month and day as this date-time.
getDate in interface ChronoZonedDateTime<C extends Chrono<C>>public LocalTime getTime()
ChronoZonedDateTimeThis returns a local time with the same hour, minute, second and nanosecond as this date-time.
getTime in interface ChronoZonedDateTime<C extends Chrono<C>>public ChronoZonedDateTime<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 ChronoZonedDateTime<C extends Chrono<C>>with in interface Temporalwith in class DefaultInterfaceTemporaladjuster - the adjuster to use, not nullpublic ChronoZonedDateTime<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 ChronoZonedDateTime<C extends Chrono<C>>plus in interface Temporalplus in class DefaultInterfaceTemporaladjuster - the adder to use, not nullpublic ChronoZonedDateTime<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 ChronoZonedDateTime<C extends Chrono<C>>minus in interface Temporalminus in class DefaultInterfaceTemporaladjuster - the subtractor to use, not nullpublic ChronoZonedDateTime<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 ChronoZonedDateTime<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 <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()
ChronoZonedDateTimeInstant.
This combines the local date-time and
offset to form an Instant.
toInstant in interface ChronoZonedDateTime<C extends Chrono<C>>Instant representing the same instant, not nullpublic long toEpochSecond()
ChronoZonedDateTime
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.
toEpochSecond in interface ChronoZonedDateTime<C extends Chrono<C>>public int compareTo(ChronoZonedDateTime<?> other)
ChronoZonedDateTime
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 Comparable.
If all the date-time objects being compared are in the same chronology, then the additional chronology stage is not required.
compareTo in interface Comparable<ChronoZonedDateTime<?>>compareTo in interface ChronoZonedDateTime<C extends Chrono<C>>other - the other date-time to compare to, not nullpublic boolean isAfter(ChronoZonedDateTime<?> other)
ChronoZonedDateTime
This method differs from the comparison in ChronoZonedDateTime.compareTo(org.threeten.bp.temporal.ChronoZonedDateTime<?>) in that it
only compares the instant of the date-time. This is equivalent to using
dateTime1.toInstant().isAfter(dateTime2.toInstant());.
isAfter in interface ChronoZonedDateTime<C extends Chrono<C>>other - the other date-time to compare to, not nullpublic boolean isBefore(ChronoZonedDateTime<?> other)
ChronoZonedDateTime
This method differs from the comparison in ChronoZonedDateTime.compareTo(org.threeten.bp.temporal.ChronoZonedDateTime<?>) in that it
only compares the instant of the date-time. This is equivalent to using
dateTime1.toInstant().isBefore(dateTime2.toInstant());.
isBefore in interface ChronoZonedDateTime<C extends Chrono<C>>other - the other date-time to compare to, not nullpublic boolean isEqual(ChronoZonedDateTime<?> other)
ChronoZonedDateTime
This method differs from the comparison in ChronoZonedDateTime.compareTo(org.threeten.bp.temporal.ChronoZonedDateTime<?>) and ChronoZonedDateTime.equals(java.lang.Object)
in that it only compares the instant of the date-time. This is equivalent to using
dateTime1.toInstant().equals(dateTime2.toInstant());.
isEqual in interface ChronoZonedDateTime<C extends Chrono<C>>other - the other date-time to compare to, not nullpublic boolean equals(Object obj)
ChronoZonedDateTime
The comparison is based on the offset date-time and the zone.
To compare for the same instant on the time-line, use ChronoZonedDateTime.compareTo(org.threeten.bp.temporal.ChronoZonedDateTime<?>).
Only objects of type ChronoZoneDateTime are compared, other types return false.
public int hashCode()
ChronoZonedDateTimepublic String toString()
ChronoZonedDateTimeString.
The output will include the full zoned date-time and the chronology ID.
public String toString(DateTimeFormatter formatter)
ChronoZonedDateTimeString using the formatter.toString in interface ChronoZonedDateTime<C extends Chrono<C>>formatter - the formatter to use, not nullCopyright © 2007-2013 ThreeTen.org. All Rights Reserved.