fork(1) download
  1. import java.time.LocalDate;
  2. import java.time.temporal.ChronoUnit;
  3.  
  4. class Main {
  5. public static void main(String args[]) {
  6. LocalDate date = LocalDate.parse("2012-01-01");
  7. System.out.println(date);
  8.  
  9. LocalDate afterFiveMonths = date.plusMonths(5);
  10. LocalDate beforeFiveMonths = date.minusMonths(5);
  11. System.out.println(afterFiveMonths);
  12. System.out.println(beforeFiveMonths);
  13.  
  14. // Alternatively,
  15. afterFiveMonths = date.plus(5, ChronoUnit.MONTHS);
  16. beforeFiveMonths = date.minus(5, ChronoUnit.MONTHS);
  17. System.out.println(afterFiveMonths);
  18. System.out.println(beforeFiveMonths);
  19. }
  20. }
Success #stdin #stdout 0.11s 49288KB
stdin
Standard input is empty
stdout
2012-01-01
2012-06-01
2011-08-01
2012-06-01
2011-08-01