JAVA计算两个Date时间差(精确到秒)
JAVA计算两个Date时间差(精确到秒)
拷贝即可使用
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 {
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;
return day + " day " + hour + "hour" + min + " min " + sec + "s";
}catch (Exception e) {
e.printStackTrace();
return null;
}
}
原文作者:面向money编程
原文地址: https://blog.csdn.net/qd2024/article/details/122804182
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
原文地址: https://blog.csdn.net/qd2024/article/details/122804182
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
相关文章