In this tutorial we will see how to add days to the LocalDate.
Java LocalDate Example 1: Adding Days to the current Date
In this example, we are adding one day to the current date. We are using now() method of LocalDate class to get the current date and then using the plusDays() method to add the specified number of days to the LocalDate.
import java.time.LocalDate; public class Example { public static void main(String[] args) { //current date LocalDate today = LocalDate.now(); //adding one day to the localdate LocalDate tomorrow = today.plusDays(1); System.out.println("Tomorrow's Date: "+tomorrow); } }
Output:
Tomorrow's Date: 2017-11-15
Example 2: Adding Days to the given LocalDate
In this example, we have the given date, which we are converting to LocalDate instance using the of() method and then we are adding the days to it using plusDays() method, similar to what we have seen in the above example.
import java.time.LocalDate; public class Example { public static void main(String[] args) { //given date LocalDate localDate = LocalDate.of(2017, 06, 22); //adding 5 days to the given localdate LocalDate newDate = localDate.plusDays(5); System.out.println("Date after addition: "+newDate); } }
Output:
Date after addition: 2017-06-27
Leave a Reply