fork(14) download
  1. import static java.time.temporal.ChronoUnit.*;
  2.  
  3. import java.time.chrono.ChronoLocalDate;
  4. import java.time.chrono.ChronoPeriod;
  5. import java.time.format.DateTimeFormatter;
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
  10. ChronoLocalDate from = ChronoLocalDate.from(formatter.parse("01/01/2000"));
  11. ChronoLocalDate to = ChronoLocalDate.from(formatter.parse("01/01/2015"));
  12. ChronoPeriod period = ChronoPeriod.between(from, to);
  13. System.out.printf("%d años, %d meses y %d días", period.get(YEARS), period.get(MONTHS), period.get(DAYS));
  14. }
  15. }
Success #stdin #stdout 0.21s 320512KB
stdin
Standard input is empty
stdout
15 años, 0 meses y 0 días