fork download
  1. import java.time.LocalDate;
  2. import java.time.Month;
  3. import java.time.Period;
  4.  
  5. public class Main {
  6. public static void main(String[] args) {
  7. Period period = LocalDate.now().until(LocalDate.of(2025, Month.OCTOBER, 18));
  8. // Default format
  9. System.out.println(period);
  10.  
  11. // Formatted output
  12. String formattedPeriod = String.format("%d year(s) %d month(s) %d day(s)", period.getYears(),
  13. period.getMonths(), period.getDays());
  14. System.out.println(formattedPeriod);
  15. }
  16. }
Success #stdin #stdout 0.1s 57084KB
stdin
Standard input is empty
stdout
P1Y6M25D
1 year(s) 6 month(s) 25 day(s)