/** * Returns a copy of this {@code ZonedDateTime} with the nano-of-second value altered. * <p> * This operates on the local time-line, * {@link LocalDateTime#withNano(int) changing the time} of the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param nanoOfSecond the nano-of-second to set in the result, from 0 to 999,999,999 * @return a {@code ZonedDateTime} based on this date-time with the requested nanosecond, not null * @throws DateTimeException if the nano value is invalid */ public ZonedDateTime withNano(int nanoOfSecond) { return resolveLocal(dateTime.withNano(nanoOfSecond)); }
/** * Returns a copy of this {@code ZonedDateTime} with the month-of-year value altered. * <p> * This operates on the local time-line, * {@link LocalDateTime#withMonth(int) changing the month} of the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param month the month-of-year to set in the result, from 1 (January) to 12 (December) * @return a {@code ZonedDateTime} based on this date-time with the requested month, not null * @throws DateTimeException if the month-of-year value is invalid */ public ZonedDateTime withMonth(int month) { return resolveLocal(dateTime.withMonth(month)); }
/** * Returns a copy of this {@code ZonedDateTime} with the hour-of-day value altered. * <p> * This operates on the local time-line, * {@link LocalDateTime#withHour(int) changing the time} of the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param hour the hour-of-day to set in the result, from 0 to 23 * @return a {@code ZonedDateTime} based on this date-time with the requested hour, not null * @throws DateTimeException if the hour value is invalid */ public ZonedDateTime withHour(int hour) { return resolveLocal(dateTime.withHour(hour)); }
/** * Returns a copy of this {@code ZonedDateTime} with the specified period in days added. * <p> * This operates on the local time-line, * {@link LocalDateTime#plusDays(long) adding days} to the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to add, may be negative * @return a {@code ZonedDateTime} based on this date-time with the days added, not null * @throws DateTimeException if the result exceeds the supported date range */ public ZonedDateTime plusDays(long days) { return resolveLocal(dateTime.plusDays(days)); }
/** * Returns a copy of this {@code ZonedDateTime} with the year value altered. * <p> * This operates on the local time-line, * {@link LocalDateTime#withYear(int) changing the year} of the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param year the year to set in the result, from MIN_YEAR to MAX_YEAR * @return a {@code ZonedDateTime} based on this date-time with the requested year, not null * @throws DateTimeException if the year value is invalid */ public ZonedDateTime withYear(int year) { return resolveLocal(dateTime.withYear(year)); }
/** * Returns a copy of this {@code ZonedDateTime} with the minute-of-hour value altered. * <p> * This operates on the local time-line, * {@link LocalDateTime#withMinute(int) changing the time} of the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param minute the minute-of-hour to set in the result, from 0 to 59 * @return a {@code ZonedDateTime} based on this date-time with the requested minute, not null * @throws DateTimeException if the minute value is invalid */ public ZonedDateTime withMinute(int minute) { return resolveLocal(dateTime.withMinute(minute)); }
/** * Returns a copy of this {@code ZonedDateTime} with the second-of-minute value altered. * <p> * This operates on the local time-line, * {@link LocalDateTime#withSecond(int) changing the time} of the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param second the second-of-minute to set in the result, from 0 to 59 * @return a {@code ZonedDateTime} based on this date-time with the requested second, not null * @throws DateTimeException if the second value is invalid */ public ZonedDateTime withSecond(int second) { return resolveLocal(dateTime.withSecond(second)); }
/** * Returns a copy of this {@code ZonedDateTime} with the day-of-month value altered. * <p> * This operates on the local time-line, * {@link LocalDateTime#withDayOfMonth(int) changing the day-of-month} of the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param dayOfMonth the day-of-month to set in the result, from 1 to 28-31 * @return a {@code ZonedDateTime} based on this date-time with the requested day, not null * @throws DateTimeException if the day-of-month value is invalid * @throws DateTimeException if the day-of-month is invalid for the month-year */ public ZonedDateTime withDayOfMonth(int dayOfMonth) { return resolveLocal(dateTime.withDayOfMonth(dayOfMonth)); }
/** * Returns a copy of this {@code ZonedDateTime} with the day-of-year altered. * <p> * This operates on the local time-line, * {@link LocalDateTime#withDayOfYear(int) changing the day-of-year} of the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param dayOfYear the day-of-year to set in the result, from 1 to 365-366 * @return a {@code ZonedDateTime} based on this date with the requested day, not null * @throws DateTimeException if the day-of-year value is invalid * @throws DateTimeException if the day-of-year is invalid for the year */ public ZonedDateTime withDayOfYear(int dayOfYear) { return resolveLocal(dateTime.withDayOfYear(dayOfYear)); }
/** * Returns a copy of this {@code ZonedDateTime} with the specified period in years added. * <p> * This operates on the local time-line, * {@link LocalDateTime#plusYears(long) adding years} to the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param years the years to add, may be negative * @return a {@code ZonedDateTime} based on this date-time with the years added, not null * @throws DateTimeException if the result exceeds the supported date range */ public ZonedDateTime plusYears(long years) { return resolveLocal(dateTime.plusYears(years)); }
/** * Returns a copy of this {@code ZonedDateTime} with the specified period in months added. * <p> * This operates on the local time-line, * {@link LocalDateTime#plusMonths(long) adding months} to the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param months the months to add, may be negative * @return a {@code ZonedDateTime} based on this date-time with the months added, not null * @throws DateTimeException if the result exceeds the supported date range */ public ZonedDateTime plusMonths(long months) { return resolveLocal(dateTime.plusMonths(months)); }
/** * Returns a copy of this {@code ZonedDateTime} with the specified period in weeks added. * <p> * This operates on the local time-line, * {@link LocalDateTime#plusWeeks(long) adding weeks} to the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param weeks the weeks to add, may be negative * @return a {@code ZonedDateTime} based on this date-time with the weeks added, not null * @throws DateTimeException if the result exceeds the supported date range */ public ZonedDateTime plusWeeks(long weeks) { return resolveLocal(dateTime.plusWeeks(weeks)); }
return resolveLocal(dateTime.truncatedTo(unit));
return resolveLocal(LocalDateTime.of((LocalDate) adjuster, dateTime.toLocalTime())); } else if (adjuster instanceof LocalTime) { return resolveLocal(LocalDateTime.of(dateTime.toLocalDate(), (LocalTime) adjuster)); } else if (adjuster instanceof LocalDateTime) { return resolveLocal((LocalDateTime) adjuster); } else if (adjuster instanceof Instant) { Instant instant = (Instant) adjuster;
if (unit instanceof ChronoUnit) { if (unit.isDateBased()) { return resolveLocal(dateTime.plus(amountToAdd, unit)); } else { return resolveInstant(dateTime.plus(amountToAdd, unit));
return resolveLocal(dateTime.with(field, newValue));