Java Program to add Period to LocalDate


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

Updated on: 30-Jul-2019

321 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements