Java计算时间差

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

/**
     * 计算时间差
     * @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();
    }