Java Program to add Period to LocalDate

Java 8Object Oriented ProgrammingProgramming

Let us first set a Period with month and days:

Period p = Period.ofMonths(5).plusDays(15);

Now set the LocalDate:

LocalDate date = LocalDate.of(2019, 4, 10);

Add period to LocalDate:

LocalDate res = date.plus(p);

Example

import java.time.LocalDate;
import java.time.Period;
public class Demo {
   public static void main(String[] args) {
      Period p = Period.ofMonths(5).plusDays(15);
      LocalDate date = LocalDate.of(2019, 4, 10);
      System.out.println("Date = "+date);
      LocalDate res = date.plus(p);
      System.out.println("Updated date = "+res);
   }
}

Output

Date = 2019-04-10
Updated date = 2019-09-25
raja
Published on 24-Apr-2019 12:01:04
Advertisements