如何在几分钟内find两个Joda-Time DateTimes之间的差异
以下是我写的方法:
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; }
现在从我的方法,你可以看到我有一个乔达时间 date 时间对象的对象名为datetime
,从我的结果我得到一个时间戳,我正在转换为jodatime punchTime
。 现在我想找出这两个date之间的差异,我该怎么做?
提前致谢
这将以毫秒为单位获得两个DateTime对象之间的差异:
DateTime d1 = new DateTime(); DateTime d2 = new DateTime(); long diffInMillis = d2.getMillis() - d1.getMillis();
就像是…
DateTime today = new DateTime(); DateTime yesterday = today.minusDays(1); Duration duration = new Duration(yesterday, today); System.out.println(duration.getStandardDays()); System.out.println(duration.getStandardHours()); System.out.println(duration.getStandardMinutes());
哪个输出
1 24 1440
要么
System.out.println(Minutes.minutesBetween(yesterday, today).getMinutes());
这可能更多的是你之后