LocalDate plusDays() Method in Java with Examples
The plusDays() method of a LocalDate class in Java is used to add the number of specified day in this LocalDate and return a copy of LocalDate. For example, 2018-12-31 plus one day would result in 2019-01-01. This instance is immutable and unaffected by this method call.
public LocalDate plusDays(long daysToAdd)
Parameters: This method accepts a single parameter daysToAdd which represents the days to add, may be negative.
Return Value: This method returns a LocalDate based on this date with the days added, not null.
Exception: This method throws DateTimeException if the result exceeds the supported date range.
Below programs illustrate the plusDays() method:
LocalDate before adding days: 2018-11-13 LocalDate after adding days: 2018-11-18
LocalDate before adding days: 2018-12-24 LocalDate after adding days: 2019-01-08
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.