fork download
  1. import java.time.LocalDate;
  2. import java.time.Period;
  3. import java.time.format.DateTimeFormatter;
  4. import java.time.format.DateTimeFormatterBuilder;
  5. import java.util.Locale;
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9. DateTimeFormatter dtf = new DateTimeFormatterBuilder()
  10. .parseCaseInsensitive()
  11. .appendPattern("d MMMM uuuu")
  12. .toFormatter(Locale.ENGLISH);
  13.  
  14. LocalDate since = LocalDate.parse("17 april 2010", dtf);
  15. LocalDate now = LocalDate.parse("15 april 2011", dtf);
  16.  
  17. Period period = Period.between(since, now);
  18.  
  19. String strPeriod = String.format("%d years %d months %d days", period.getYears(), period.getMonths(),
  20. period.getDays());
  21. System.out.println(strPeriod);
  22. }
  23. }
Success #stdin #stdout 0.13s 52648KB
stdin
Standard input is empty
stdout
0 years 11 months 29 days