Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Add days to date in java 8 LocalDate

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

The post How to Add days to date in java 8 LocalDate appeared first on Candidjava -Core Java, Servlet, Jsp, Hibernate,Spring,.



This post first appeared on Core Java,Servlet,Jsp,Struts,Hibernate,Spring Fram, please read the originial post: here

Share the post

How to Add days to date in java 8 LocalDate

×

Subscribe to Core Java,servlet,jsp,struts,hibernate,spring Fram

Get updates delivered right to your inbox!

Thank you for your subscription

×