fork 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(2024, 2, 22);
  7. LocalDate later = LocalDate.of(2024, 5, 5);
  8.  
  9. System.out.println("Now: " + now);
  10. System.out.println("Later: " + later);
  11. System.out.println("Months between now and later: " + MONTHS.between(now, later));
  12. }
  13. }
Success #stdin #stdout 0.15s 56244KB
stdin
Standard input is empty
stdout
Now: 2024-02-22
Later: 2024-05-05
Months between now and later: 2