を使用した別のアプローチTimeUnit
final SimpleDateFormat fmt = new SimpleDateFormat("dd/MM/yyyy HH:mm");
final Date old = fmt.parse("10/7/2013 10:10");
final Date now = fmt.parse("12/7/2013 12:12");
long dif = now.getTime() - old.getTime();
final long days = TimeUnit.MILLISECONDS.toDays(dif);
dif -= TimeUnit.DAYS.toMillis(days);
final long hours = TimeUnit.MILLISECONDS.toHours(dif);
dif -= TimeUnit.HOURS.toMillis(hours);
long mins = TimeUnit.MILLISECONDS.toMinutes(dif);
System.out.format("%d days, %d hours, %d mins\n", days, hours, mins);
どちらが正しく印刷されますか:
2 days, 2 hours, 2 mins