This code will calculate the time difference.
We need to pass the two date objects which represents the Start and End time.
It will return an array which in turn contain the difference details in Hours,Minutes,Seconds in Array Index 0,1 and 2 respectively.
We need to pass the two date objects which represents the Start and End time.
It will return an array which in turn contain the difference details in Hours,Minutes,Seconds in Array Index 0,1 and 2 respectively.
public Long[] calculateExecutionTime(java.util.Date startTime, java.util.Date endTime) { Long timeDetailsArray[] = new Long[3]; long difference = endTime.getTime() - startTime.getTime(); long hours, minutes, timeInSeconds; long seconds; difference = difference / 1000; timeInSeconds = difference; hours = timeInSeconds / 3600; timeInSeconds = timeInSeconds - (hours * 3600); minutes = timeInSeconds / 60; timeInSeconds = timeInSeconds - (minutes * 60); seconds = timeInSeconds; timeDetailsArray[0] = hours; timeDetailsArray[1] = minutes; timeDetailsArray[2] = seconds; System.out.println( timeDetailsArray[0] +" Hour(s) " + timeDetailsArray[1] +" Minute(s) "+ timeDetailsArray[2] + "Seconds "); return timeDetailsArray; }