JDK1.8 LocalDateTime 计算2个时间差
2021/4/13 11:21:28 | 阅1705 | 来源:好空间网络 [打印] [关闭] |
/** * 计算一个订单的从开始到结束用了多少天,如果服务中的订单则以当天日期计算截至日期 * * @param strTime * @param endTime * @param status * @return */ public static long getOrderDay(LocalDateTime strTime, LocalDateTime endTime, String status) { long day = 0; if ("服务中".equals(status)) { // 今天日期 LocalDateTime date = LocalDateTime.now(); endTime = date; } Duration duration = Duration.between(strTime,endTime); day = duration.toDays(); //相差的天数 return day; }