Java计算时间差
2018-07-20 来源:open-open
/**
* 计算时间差
* @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();
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐