如何找到两个乔达之间的区别

以下是我写的方法:

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对象之间的差异:

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());

这可能更多的是你在追求什么


就像是...

Minutes.minutesBetween(getStart(), getEnd()).getMinutes();
链接地址: http://www.djcxy.com/p/36727.html

上一篇: How to find difference between two Joda

下一篇: Find the difference in days between a java.util.Date and a Joda