使用场景: 发货日期与到货日期 计算运输时长
代码:
private String getMinuteTime(String startTime, String endTime) {
String minuteTime = null;
if (StrUtil.isNotBlank(startTime) && StrUtil.isNotBlank(endTime)) {
long minute = DateUtil.between(DateUtil.parse(startTime), DateUtil.parse(endTime), DateUnit.MINUTE);
long minuteDay = 24 * 60;
long day = minute / minuteDay;
long hour = (minute - day * minuteDay) / 60;
long minutes = minute - day * minuteDay - hour * 60;
if (day > 0) {
minuteTime = day + "天";
}
if (hour > 0) {
minuteTime = minuteTime + hour + "时";
}
if (minutes > 0) {
minuteTime = minuteTime + minutes + "分";
}
}
return minuteTime;
}
输出结果: