1 package org.kuali.ole.deliver.calendar.service;
2
3 import java.sql.Timestamp;
4 import java.text.DateFormat;
5 import java.text.ParseException;
6 import java.text.SimpleDateFormat;
7 import java.util.Calendar;
8
9
10
11
12
13
14
15
16
17 public class DateUtil {
18 public static Timestamp addDays(Timestamp date, int days) {
19 Calendar cal = Calendar.getInstance();
20 cal.setTime(date);
21 cal.add(Calendar.DATE, days);
22 return new Timestamp(cal.getTime().getTime());
23
24
25 }
26
27 public static Timestamp addHours(Timestamp date, int numOfHours) {
28
29 Long milliSecInAnHour = new Long(60 * 60 * 1000);
30 Timestamp newTS = new Timestamp(date.getTime());
31 long milliSecToAdd = milliSecInAnHour * numOfHours;
32 long newTimeMilliSec = newTS.getTime();
33 newTS.setTime(newTimeMilliSec + milliSecToAdd);
34 return newTS;
35
36
37 }
38
39
40 private static final DateFormat TWELVE_TF = new SimpleDateFormat("hh:mma");
41
42 private static final DateFormat TWENTY_FOUR_TF = new SimpleDateFormat("HH:mm");
43
44 public static String convertTo24HoursFormat(String twelveHourTime)
45 throws ParseException {
46 return TWENTY_FOUR_TF.format(
47 TWELVE_TF.parse(twelveHourTime));
48 }
49
50 public static String convertTo12HoursFormat(String twentyFourHourTime)
51 throws ParseException {
52 return TWELVE_TF.format(
53 TWENTY_FOUR_TF.parse(twentyFourHourTime));
54 }
55
56
57 }