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 import java.util.Calendar;
20 import java.util.Date;
21
22 public class DateTimeUtil {
23
24 public static String formatTime(long endTime, long startTime) {
25 long milliseconds = endTime - startTime;
26 return formatTime(milliseconds);
27 }
28
29 public static String formatTime(long timeInMillisec) {
30 long hours;
31 long minutes;
32 long seconds;
33 long milliseconds = timeInMillisec;
34 double secAndMilliSec = (double) timeInMillisec / 1000;
35 double milliSec = secAndMilliSec - (long) secAndMilliSec;
36 DecimalFormat df = new DecimalFormat("#.###");
37 seconds = (milliseconds / 1000);
38
39 minutes = seconds / 60;
40 seconds = seconds - minutes * 60;
41 hours = minutes / 60;
42 minutes = minutes - hours * 60;
43 secAndMilliSec = (double) seconds + Double.valueOf(df.format(milliSec));
44 String timeTaken = hours + ":" + minutes + ":" + Double.valueOf(df.format(secAndMilliSec));
45 return timeTaken;
46 }
47
48 public static Date formatDate(Date date){
49 Calendar calendar = Calendar.getInstance();
50 calendar.setTime(date);
51 return calendar.getTime();
52 }
53
54 public static Date formateDateWithStartTimeOfTheDay(Date date){
55 Calendar calendar = Calendar.getInstance();
56 calendar.setTime(date);
57 calendar.set(Calendar.HOUR_OF_DAY, 00);
58 calendar.set(Calendar.MINUTE, 01);
59 calendar.set(Calendar.SECOND, 01);
60 calendar.set(Calendar.MILLISECOND, 01);
61 Date formatedDate = DateTimeUtil.formatDate(calendar.getTime());
62 return formatedDate;
63 }
64
65 public static Date formateDateWithEndTimeOfTheDay(Date date){
66 Calendar calendar = Calendar.getInstance();
67 calendar.setTime(date);
68 calendar.set(Calendar.HOUR_OF_DAY, 23);
69 calendar.set(Calendar.MINUTE, 59);
70 calendar.set(Calendar.SECOND, 59);
71 calendar.set(Calendar.MILLISECOND, 59);
72 Date formatedDate = DateTimeUtil.formatDate(calendar.getTime());
73 return formatedDate;
74 }
75
76
77
78 }