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