1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.util; |
12 | |
|
13 | |
import org.mule.config.i18n.CoreMessages; |
14 | |
|
15 | |
import java.text.ParsePosition; |
16 | |
import java.text.SimpleDateFormat; |
17 | |
import java.util.Date; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | 0 | public class DateUtils extends org.apache.commons.lang.time.DateUtils |
25 | |
{ |
26 | |
|
27 | |
public static String getTimeStamp(String format) |
28 | |
{ |
29 | |
|
30 | 2 | SimpleDateFormat formatter = new SimpleDateFormat(format); |
31 | 2 | Date currentTime = new Date(); |
32 | 2 | return formatter.format(currentTime); |
33 | |
} |
34 | |
|
35 | |
public static String formatTimeStamp(Date dateTime, String format) |
36 | |
{ |
37 | |
|
38 | 2 | SimpleDateFormat formatter = new SimpleDateFormat(format); |
39 | 2 | return formatter.format(dateTime); |
40 | |
} |
41 | |
|
42 | |
public static String getStringFromDate(Date date, String format) |
43 | |
{ |
44 | |
|
45 | |
|
46 | 4 | SimpleDateFormat formatter = new SimpleDateFormat(format); |
47 | 4 | return formatter.format(date); |
48 | |
} |
49 | |
|
50 | |
public static Date getDateFromString(String date, String format) |
51 | |
{ |
52 | |
|
53 | |
|
54 | 2 | SimpleDateFormat formatter = new SimpleDateFormat(format); |
55 | 2 | ParsePosition pos = new ParsePosition(0); |
56 | |
|
57 | |
|
58 | 2 | return formatter.parse(date, pos); |
59 | |
} |
60 | |
|
61 | |
public static String getFormattedDuration(long mills) |
62 | |
{ |
63 | 0 | long days = mills / 86400000; |
64 | 0 | mills = mills - (days * 86400000); |
65 | 0 | long hours = mills / 3600000; |
66 | 0 | mills = mills - (hours * 3600000); |
67 | 0 | long mins = mills / 60000; |
68 | 0 | mills = mills - (mins * 60000); |
69 | 0 | long secs = mills / 1000; |
70 | 0 | mills = mills - (secs * 1000); |
71 | |
|
72 | 0 | StringBuffer bf = new StringBuffer(60); |
73 | 0 | bf.append(days).append(" ").append(CoreMessages.days().getMessage()).append(", "); |
74 | 0 | bf.append(hours).append(" ").append(CoreMessages.hours().getMessage()).append(", "); |
75 | 0 | bf.append(mins).append(" ").append(CoreMessages.minutes().getMessage()).append(", "); |
76 | 0 | bf.append(secs).append(".").append(mills).append(" ").append(CoreMessages.seconds().getMessage()); |
77 | 0 | return bf.toString(); |
78 | |
} |
79 | |
|
80 | |
} |