1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.utility;
17
18 import java.text.DecimalFormat;
19
20 public class DateTimeUtil {
21
22 public static String formatTime(long endTime, long startTime) {
23 long milliseconds = endTime - startTime;
24 return formatTime(milliseconds);
25 }
26
27 public static String formatTime(long timeInMillisec) {
28 long hours;
29 long minutes;
30 long seconds;
31 long milliseconds = timeInMillisec;
32 double secAndMilliSec = (double) timeInMillisec / 1000;
33 double milliSec = secAndMilliSec - (long) secAndMilliSec;
34 DecimalFormat df = new DecimalFormat("#.###");
35 seconds = (milliseconds / 1000);
36
37 minutes = seconds / 60;
38 seconds = seconds - minutes * 60;
39 hours = minutes / 60;
40 minutes = minutes - hours * 60;
41 secAndMilliSec = (double) seconds + Double.valueOf(df.format(milliSec));
42 String timeTaken = hours + ":" + minutes + ":" + Double.valueOf(df.format(secAndMilliSec));
43 return timeTaken;
44 }
45
46 }