Date and Time

How to Add days to date in java 8 LocalDate

Table of Contents

Program

import java.time.LocalDate;
import java.text.ParseException;
public class LocalDatePlusDays
{
	public static void main(String args[]) throws ParseException 
	{
		LocalDate date = LocalDate.parse("2019-07-15");
		LocalDate date2 = date.plusDays(10);
		System.out.println("After adding 10 days: "+date2);
	}
}

Output

After adding 10 days: 2019-07-25

Description

public LocalDateTime plusDays​(long days)

Returns a copy of this LocalDateTime with the specified number of days added.
This method adds the specified amount to the days field incrementing the month and year fields as necessary to ensure the result remains valid. The result is only invalid if the maximum/minimum year is exceeded.

For example, 2008-12-31 plus one day would result in 2009-01-01.

This instance is immutable and unaffected by this method call.

Parameters:

days – the days to add, may be negative

Returns:

a LocalDateTime based on this date-time with the days added, not null

Throws:

DateTimeException – if the result exceeds the supported date range