仅比较两个日期的时间部分,忽略日期部分
给定两个 Date 对象,仅比较其时间部分之间的差异,完全忽略年、月和日,这有什么好方法?
这与这个问题完全相反。
更新:以下是最终代码,供将来参考:
private long differenceBetween(Date currentTime, Date timeToRun)
{
Calendar currentCal = Calendar.getInstance();
currentCal.setTime(currentTime);
Calendar runCal = Calendar.getInstance();
runCal.setTime(timeToRun);
runCal.set(Calendar.DAY_OF_MONTH, currentCal.get(Calendar.DAY_OF_MONTH));
runCal.set(Calendar.MONTH, currentCal.get(Calendar.MONTH));
runCal.set(Calendar.YEAR, currentCal.get(Calendar.YEAR));
return currentCal.getTimeInMillis() - runCal.getTimeInMillis();
}