Java Data Type How to - Add Period to LocalDate








Question

We would like to know how to add Period to LocalDate.

Answer

//from   ww w  .j av a  2s  .  c o  m
import java.time.LocalDate;
import java.time.Period;

public class Main {
  public static void main(String[] args) {
    Period twoMonthsAndFiveDays = Period.ofMonths(2).plusDays(5);
    LocalDate sixthOfJanuary = LocalDate.of(2014, 1, 6);

    LocalDate eleventhOfMarch = sixthOfJanuary.plus(twoMonthsAndFiveDays);

    System.out.println(eleventhOfMarch);
  }
}

The code above generates the following result.