The calculation will do its best to only change the year field retaining the same month of year. However, in certain circumstances, it may be necessary to alter smaller fields. For example, 2008-02-29 minus one year cannot result in 2007-02-29, so the day of month is adjusted to 2007-02-28.
The following three lines are identical in effect:
DateTime subtracted = dt.minusYears(6); DateTime subtracted = dt.minus(Period.years(6)); DateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6);
This datetime instance is immutable and unaffected by this method call. @param years the amount of years to subtract, may be negative @return the new datetime minus the increased years @since 1.1
This LocalDate instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDate subtracted = dt.minusYears(6); LocalDate subtracted = dt.minus(Period.years(6)); LocalDate subtracted = dt.withFieldAdded(DurationFieldType.years(), -6);@param years the amount of years to subtract, may be negative @return the new LocalDate minus the increased years
This method subtracts the specified amount from the years field in three steps:
For example, 2008-02-29 (leap year) minus one year would result in the invalid date 2007-02-29 (standard year). Instead of returning an invalid result, the last valid day of the month, 2007-02-28, is selected instead.
This instance is immutable and unaffected by this method call. @param yearsToSubtract the years to subtract, may be negative @return a {@code LocalDate} based on this date with the years subtracted, not null @throws DateTimeException if the result exceeds the supported date range
This instance is immutable and unaffected by this method call. @param yearsToSubtract the years to subtract, may be negative @return a {@code Year} based on this year with the period subtracted, not null @throws DateTimeException if the result exceeds the supported year range
This instance is immutable and unaffected by this method call. @param yearsToSubtract the years to subtract, may be negative @return a {@code YearMonth} based on this year-month with the years subtracted, not null @throws DateTimeException if the result exceeds the supported range
|
|
|
|
|
|
|
|
|
|
|
|
|
|