The calculation will do its best to only change the month field retaining the same day of month. However, in certain circumstances, it may be necessary to alter smaller fields. For example, 2007-03-31 plus one month cannot result in 2007-04-31, so the day of month is adjusted to 2007-04-30.
The following three lines are identical in effect:
DateTime added = dt.plusMonths(6); DateTime added = dt.plus(Period.months(6)); DateTime added = dt.withFieldAdded(DurationFieldType.months(), 6);
This datetime instance is immutable and unaffected by this method call. @param months the amount of months to add, may be negative @return the new datetime plus the increased months @since 1.1
This LocalDate instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDate added = dt.plusMonths(6); LocalDate added = dt.plus(Period.months(6)); LocalDate added = dt.withFieldAdded(DurationFieldType.months(), 6);@param months the amount of months to add, may be negative @return the new LocalDate plus the increased months
This period instance is immutable and unaffected by this method call. @param months the amount of months to add, may be negative @return the new period plus the increased months @throws UnsupportedOperationException if the field is not supported
This date instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
YearMonthDay added = dt.plusMonths(6); YearMonthDay added = dt.plus(Period.months(6)); YearMonthDay added = dt.withFieldAdded(DurationFieldType.months(), 6);@param months the amount of months to add, may be negative @return the new date plus the increased months @since 1.1
This method adds the specified amount to the months field in three steps:
For example, 2007-03-31 plus one month would result in the invalid date 2007-04-31. Instead of returning an invalid result, the last valid day of the month, 2007-04-30, is selected instead.
This instance is immutable and unaffected by this method call. @param monthsToAdd the months to add, may be negative @return a {@code LocalDate} based on this date with the months added, not null @throws DateTimeException if the result exceeds the supported date range
This instance is immutable and unaffected by this method call. @param monthsToAdd the months to add, may be negative @return a {@code YearMonth} based on this year-month with the months added, not null @throws DateTimeException if the result exceeds the supported range
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.
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.
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|