平时总是碰到一些情况,需要计算两个时间之间的差。遇到的多了,就干脆自己写一个静态方法。
技术实现:
public class TimeDifferentUtil {
public static String getTimeDifferent(Date startTime, Date endTime) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long days = 0;
long hours = 0;
long minutes = 0;
if(!ObjectUtil.isEmpty(startTime)&&!ObjectUtil.isEmpty(endTime)){
long inpecTimeHS = endTime.getTime()-startTime.getTime();
days = inpecTimeHS/(1000 * 60 * 60 * 24);
hours = (inpecTimeHS-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
minutes = (inpecTimeHS-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
return days+"天"+hours+"小时"+minutes+"分钟";
}
return "";
}
}



