JAVA中如何对两个日期时间进行运算?

在程序中的某一段记录系统时间
StarTime = new SimpleDateFormat("yyyyMMddhh:mm:ss").format(System.currentTimeMillis());
假设记录时间为20160926 21:39:40
然后在程序的另一段再次记录系统时间
EndTime = new SimpleDateFormat("yyyyMMddhh:mm:ss").format(System.currentTimeMillis());
假设记录时间为20160926 21:55:47
最后想要通过这两个时间点求时间差,输出格式为00:00:00,例如上面两个时间相减后得到的差值为00:16:07,即16分钟7秒
求问各位大神,这样的程序该怎么写?

/** 
     * 计算两个日期之间相差的天数 
     * @param date1 
     * @param date2 
     * @return 
     */  
    public static int daysBetween(Date date1,Date date2)  
    {  
        Calendar cal = Calendar.getInstance();  
        cal.setTime(date1);  
        long time1 = cal.getTimeInMillis();               
        cal.setTime(date2);  
        long time2 = cal.getTimeInMillis();       
        long between_days=(time2-time1)/(1000*3600*24);  
          
       return Integer.parseInt(String.valueOf(between_days));         
    }

温馨提示:答案为网友推荐,仅供参考
相似回答