DateTime의 두 개체가 있습니다.차이 의 기간 을 찾아야하는 있습니다 .
다음 코드가 있지만 다음과 같이 예상되는 결과를 얻기 위해 계속하는 방법을 모르겠습니다.
예
11/03/14 09:30:58
11/03/14 09:33:43
elapsed time is 02 minutes and 45 seconds
-----------------------------------------------------
11/03/14 09:30:58
11/03/15 09:30:58
elapsed time is a day
-----------------------------------------------------
11/03/14 09:30:58
11/03/16 09:30:58
elapsed time is two days
-----------------------------------------------------
11/03/14 09:30:58
11/03/16 09:35:58
elapsed time is two days and 05 mintues
암호
String dateStart = "11/03/14 09:29:58";
String dateStop = "11/03/14 09:33:43";
Custom date format
SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
Date d1 = null;
Date d2 = null;
try {
d1 = format.parse(dateStart);
d2 = format.parse(dateStop);
} catch (ParseException e) {
e.printStackTrace();
}
// Get msec from each, and subtract.
long diff = d2.getTime() - d1.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000);
System.out.println("Time in seconds: " + diffSeconds + " seconds.");
System.out.println("Time in minutes: " + diffMinutes + " minutes.");
System.out.println("Time in hours: " + diffHours + " hours.");