下面是我写的方法:
public List<Map<String, Object>> loadNotYetInEmployee(int shift, Date date, int transitionVal, String type, User user) { DateTime datetime = new DateTime(date); datetime = datetime .plus(Period.minutes(shiftTiming.getSession1InTime())); List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); sql = SqlMapUtils.getSql("attendance.attendancestatus.latein", parameters); result = getJdbcTemplate().queryForList(sql); for (int i = 0; i < result.size(); i++) { Date punchInTime = (Date) result.get(i).get("punchtime"); DateTime punchTime = new DateTime(punchInTime); } return result; }
现在,从我的方法中,你可以看到我在名为的对象中有一个Joda-Time DateTime对象datetime,从结果中,我得到一个时间戳,该时间戳将转换为jodatime punchTime。现在,我想找出这两个日期之间的差异,该怎么办?
datetime
punchTime
这将使你获得两个DateTime对象之间的差(以毫秒为单位):
DateTime d1 = new DateTime(); DateTime d2 = new DateTime(); long diffInMillis = d2.getMillis() - d1.getMillis();