fork(3) download
  1. import java.time.*;
  2. import static java.time.temporal.ChronoUnit.MONTHS;
  3.  
  4. class MyClass {
  5. public static void main(String[] args) {
  6. LocalDate now = LocalDate.of(2020, 7, 31);
  7. LocalDate later = now.plusMonths(2);
  8.  
  9. System.out.println("Now: " + now);
  10. System.out.println("Later: " + later);
  11. System.out.println("Months between now and later: " + MONTHS.between(YearMonth.from(now), YearMonth.from(later)));
  12. }
  13. }
Success #stdin #stdout 0.15s 37156KB
stdin
Standard input is empty
stdout
Now: 2020-07-31
Later: 2020-09-30
Months between now and later: 2