/** * Gets the local time part of this date-time. * <p> * This returns a local time with the same hour, minute, second and * nanosecond as this date-time. * * @return the time part of this date-time, not null */ public LocalTime toLocalTime() { return toLocalDateTime().toLocalTime(); }
/** * Gets the local date part of this date-time. * <p> * This returns a local date with the same year, month and day * as this date-time. * * @return the date part of this date-time, not null */ public D toLocalDate() { return toLocalDateTime().toLocalDate(); }
@Override public ValueRange range(TemporalField field) { if (field instanceof ChronoField) { if (field == INSTANT_SECONDS || field == OFFSET_SECONDS) { return field.range(); } return toLocalDateTime().range(field); } return field.rangeRefinedBy(this); }
/** * A hash code for this date-time. * * @return a suitable hash code */ @Override public int hashCode() { return toLocalDateTime().hashCode() ^ getOffset().hashCode() ^ Integer.rotateLeft(getZone().hashCode(), 3); }
@Override public int get(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case INSTANT_SECONDS: throw new UnsupportedTemporalTypeException("Field too large for an int: " + field); case OFFSET_SECONDS: return getOffset().getTotalSeconds(); } return toLocalDateTime().get(field); } return super.get(field); }
@Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case INSTANT_SECONDS: return toEpochSecond(); case OFFSET_SECONDS: return getOffset().getTotalSeconds(); } return toLocalDateTime().getLong(field); } return field.getFrom(this); }
@Override public long until(Temporal endExclusive, TemporalUnit unit) { @SuppressWarnings("unchecked") ChronoZonedDateTime<D> end = (ChronoZonedDateTime<D>) toLocalDate().getChronology().zonedDateTime(endExclusive); if (unit instanceof ChronoUnit) { end = end.withZoneSameInstant(offset); return dateTime.until(end.toLocalDateTime(), unit); } return unit.between(this, end); }
throw new DateTimeException("ChronoZonedDateTime must use the effective parsed zone: " + zone); resolvedObject = czdt.toLocalDateTime();
/** * Outputs this date-time as a {@code String}. * <p> * The output will include the full zoned date-time and the chronology ID. * * @return a string representation of this date-time, not null */ @Override public String toString() { String str = toLocalDateTime().toString() + getOffset().toString(); if (getOffset() != getZone()) { str += '[' + getZone().toString() + ']'; } return str; }
/** * Compares this date-time to another date-time, including the chronology. * <p> * 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 {@link Comparable}. * <p> * If all the date-time objects being compared are in the same chronology, then the * additional chronology stage is not required. * * @param other the other date-time to compare to, not null * @return the comparator value, negative if less, positive if greater */ @Override public int compareTo(ChronoZonedDateTime<?> other) { int cmp = Jdk8Methods.compareLongs(toEpochSecond(), other.toEpochSecond()); if (cmp == 0) { cmp = toLocalTime().getNano() - other.toLocalTime().getNano(); if (cmp == 0) { cmp = toLocalDateTime().compareTo(other.toLocalDateTime()); if (cmp == 0) { cmp = getZone().getId().compareTo(other.getZone().getId()); if (cmp == 0) { cmp = toLocalDate().getChronology().compareTo(other.toLocalDate().getChronology()); } } } } return cmp; }