2016-05-26 53 views

回答

0

可以使用的SimpleDateFormat類給一個完整的最新信息:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 
     Date startDate = df.parse("2016-05-24 17:50:10"); 
     Date endDate = df.parse("2016-05-25 19:05:15"); 
     long diff = endDate.getTime() - startDate.getTime(); 

     int timeInSeconds = (int) (diff/1000); 
     int hours, minutes, seconds; 
     hours = timeInSeconds/3600; 
     timeInSeconds = timeInSeconds - (hours * 3600); 
     minutes = timeInSeconds/60; 
     timeInSeconds = timeInSeconds - (minutes * 60); 
     seconds = timeInSeconds; 

     System.out.println(String.format("%d:%d':%d\"", hours, minutes, seconds)); 
相關問題