Java - Add years, months, and days to a LocalDate.

Introduction

If you add days to a LocalDate, the month and year fields are adjusted to keep the result a valid date.

Demo

import java.time.LocalDate;
import java.time.Month;

public class Main {
  public static void main(String[] args) {
    LocalDate ld1 = LocalDate.of(2014, Month.JANUARY, 31);
    LocalDate ld2 = ld1.plusDays(30);
    LocalDate ld3 = ld1.plusDays(555);
    System.out.println(ld1);//from w ww.  ja v  a 2  s.c om
    System.out.println(ld2);
    System.out.println(ld3);
  }
}

Result

Related Topic