LocalDate minusWeeks() method in Java with Examples
The minusWeeks() method of a LocalDate class in Java is used to subtract the number of specified week from this LocalDate and return a copy of LocalDate.For example, 2018-12-24 minus one week would result in 2018-12-17. This instance is immutable and unaffected by this method call.
public LocalDate minusWeeks(long weeksToSubtract)
Parameters: This method accepts a single parameter weeksToSubtract which represents the weeks to subtract, may be negative.
Return Value: This method returns a LocalDate based on this date with the weeks subtracted, not null.
Exception: This method throws DateTimeException if the result exceeds the supported date range.
Below programs illustrate the minusWeeks() method:
LocalDate before subtracting weeks: 2018-12-26 LocalDate after subtracting weeks: 2018-12-12
LocalDate before subtracting weeks: 2018-12-24 LocalDate after subtracting weeks: 2019-03-25