计算时间差

     dispatchedTimeStr -> 2020-06-03 17:16:20
//                requestArrivalTimeStr -> 2020-06-04 18:00:00
                String dispatchedTimeStr = o.getString("dispatchedTimeStr");
                String requestArrivalTimeStr = o.getString("requestArrivalTimeStr");

                LocalDateTime dispatchedTime = LocalDateTime.parse(dispatchedTimeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

                LocalDateTime requestArrivalTime = LocalDateTime.parse(requestArrivalTimeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
                // 求两个时间之间的差值
                Duration d = Duration.between(dispatchedTime, requestArrivalTime);
                // 大于5小时的不处理
                if (d.toHours() > 5) {
                    continue;
                }

 

你可能感兴趣的:(计算时间差)