日付間の時差を計算しようとしています:
public static void main(String args[])
{
String start = "2013-03-10 10:28:47.000000";
String end = "2013-04-07 09:54:08.054577";
CalculateDuration calc = new CalculateDuration();
calc.calculateDiffrenceInMinutes(start,end);
}
public int calculateDiffrenceInMinutes(String start_time, String end_time)
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d1 = null;
Date d2 = null;
try {
d1 = format.parse(start_time);
d2 = format.parse(end_time);
} catch (ParseException e) {
e.printStackTrace();
}
// Get msec from each, and subtract.
int diff = (int) d2.getTime() - (int)d1.getTime();
int diffSeconds = (int) (diff / 1000);
int diffMinutes = (int) (diff / (60 * 1000));
int diffHours = (int) (diff / (60 * 60 * 1000));
return diffMinutes;
}
何らかの理由で、終了日が開始日よりも後であっても、負の出力を示す例を理解できません。
何か案は?