/**
* @Author:
* @Description:
* @Date: 2019/4/10 19:01
* @Modified By:
*/
@Slf4j
public class DateUtils {
private static final long nd = 1000 * 24 * 60 * 60;
private static final long nh = 1000 * 60 * 60;
private static final long nm = 1000 * 60;
/**
* 计算两个时间段时间差,精确到秒
* @param startTime 2019-04-10 17:16:11
* @param endTime 2019-04-10 17:28:17
* @return
*/
public static String computationTime(Date startTime, Date endTime){
try {
log.info("开始时间->{}, 结束时间->{}",startTime, endTime);
long diff = endTime.getTime() - startTime.getTime();
long day = diff / nd;
long hour = diff % nd / nh;
long min = diff % nd % nh / nm;
long sec = diff % nd % nh % nm / 1000;
String str = day + "天" + hour + "小时" + min + "分钟" + sec + "秒";
return str;
}catch (Exception e) {
log.info("计算两个时间段时间差出错了, {}",e);
return null;
}
}
}