What is the output from the following code
LocalDate ld1 = LocalDate.of(2014, Month.JANUARY, 31); LocalDate ld2 = ld1.plusMonths(1); System.out.println(ld1); System.out.println(ld2);
2014-02-28
After adding the month, the result is checked if it is a valid date.
If it is not a valid date, the day of month is adjusted to the last day of the month.
In this case, the result would be 2014-02-28.
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.plusMonths(1); System.out.println(ld1);// www .j av a 2 s . co m System.out.println(ld2); } }