/** * 计算时间差 * @param begin * @param end * @return 返回格式,"hh:mm:ss" */ public String getTimeDifference(Date begin,Date end) { long between=(end.getTime()-begin.getTime())/1000;//除以1000是为了转换成秒 long hour=between%(24*3600)/3600; long minute=between%3600/60; long second=between%60; StringBuffer time=new StringBuffer(); if(hour!=0){ time.append(hour+":"); } if(time.length()!=0){ time.append(String.format("%02d:", minute)); }else if(minute!=0){ time.append(String.format("%d:", minute)); } if(time.length()!=0){ time.append(String.format("%02d", second)); }else{ time.append(second); } return time.toString(); }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/10900.html