/** * Returns a copy of this {@code OffsetDateTime} with the month-of-year altered. * The offset does not affect the calculation and will be the same in the result. * If the day-of-month is invalid for the year, it will be changed to the last valid day of the month. * <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 an {@code OffsetDateTime} based on this date-time with the requested month, not null * @throws DateTimeException if the month-of-year value is invalid */ public OffsetDateTime withMonth(int month) { return with(dateTime.withMonth(month), offset); }
/** * Returns a copy of this {@code OffsetDateTime} with the month-of-year altered. * The offset does not affect the calculation and will be the same in the result. * If the day-of-month is invalid for the year, it will be changed to the last valid day of the month. * <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 an {@code OffsetDateTime} based on this date-time with the requested month, not null * @throws DateTimeException if the month-of-year value is invalid */ public OffsetDateTime withMonth(int month) { return with(dateTime.withMonth(month), offset); }
/** * 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 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)); }
LocalDateTime ldt = LocalDateTime.now(zoneId) .with(TemporalAdjusters.firstInMonth(transitionRuleDayOfWeek)) .withMonth(transitionRuleMonthValue) .with(transitionRule.getLocalTime()); Month month = ldt.getMonth(); observance.getProperties().add(offsetTo); observance.getProperties().add(rrule); observance.getProperties().add(new DtStart(String.format(DATE_TIME_TPL, startDate.withMonth(transitionRule.getMonth().getValue()) .withDayOfMonth(transitionRule.getDayOfMonthIndicator()) .with(transitionRule.getDayOfWeek()))));