LAST UPDATED: NOVEMBER 27, 2020
Java LocalDate plusDays() Method
Java plusDays() method is used to plus the specified number of days to a date. It adds the days and returns a new LocalDate
. For example, 2009年01月10日 plus one day would result in 2009年01月11日.
It takes a long type argument that represents the number of days and returns a new LocalDate
. The syntax of the method is given below.
Syntax
public LocalDate plusDays(long daysToAdd)
Parameters:
It takes a parameter of a long type.
Returns:
It returns a localdate after adding the days.
Time for an Example:
Let's take an example to add days to a date. Here, we are adding 2 days to date by using the plusDays()
method and we get a new date as a result.
import java.time.LocalDate;
public class DateDemo {
public static void main(String[] args){
LocalDate localDate = LocalDate.of(2018, 10, 10);
System.out.println(localDate);
localDate = localDate.plusDays(2);
System.out.println("New date : "+localDate);
}
}
2018年10月10日
New date : 2018年10月12日
Time for another Example:
Let's take another example to add the specified days to a date. Here, we are adding 2 days to the current date. we used now()
method to get the current date and plusDays()
method to get a new date after adding the days.
import java.time.LocalDate;
public class DateDemo {
public static void main(String[] args){
LocalDate localDate = LocalDate.now();
System.out.println(localDate);
localDate = localDate.plusDays(2);
System.out.println("New date : "+localDate);
}
}
2020年06月17日
New date : 2020年06月19日
Live Example:
Try with a live example, execute the code instantly with our powerful Online Java Compiler.
[フレーム]