Rev 15 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 15 | Rev 73 | ||
|---|---|---|---|
| 1 | /** |
1 | /** |
| 2 | * File created by Jimmy |
2 | * File created by Jimmy |
| 3 | * at 2003-dec-28 14:48:30 |
3 | * at 2003-dec-28 14:48:30 |
| 4 | */ |
4 | */ |
| 5 | package Macbeth.Utilities; |
5 | package Macbeth.Utilities; |
| 6 | 6 | ||
| 7 | import java.util.Calendar; |
7 | import java.util.Calendar; |
| 8 | import java.util.TimeZone; |
8 | import java.util.TimeZone; |
| 9 | 9 | ||
| 10 | /** |
10 | /** |
| 11 | * Date and time utility functions. |
11 | * Date and time utility functions. |
| 12 | * @author Jimmy |
12 | * @author Jimmy |
| 13 | */ |
13 | */ |
| 14 | public class MyDateTime { |
14 | public class MyDateTime { |
| 15 | 15 | ||
| 16 | /** |
16 | /** |
| 17 | * Gets current date and time formatted as a string. |
17 | * Gets current date and time formatted as a string. |
| 18 | * @param format The date- and time-format you want to use. |
18 | * @param format The date- and time-format you want to use. |
| 19 | * An example would be "yyyy-MM-dd HH:mm:ss". See |
19 | * An example would be "yyyy-MM-dd HH:mm:ss". See |
| 20 | * @return Current date and time as a string. |
20 | * @return Current date and time as a string. |
| 21 | */ |
21 | */ |
| 22 | public static String now(String format) { |
22 | public static String now(String format) { |
| 23 | Calendar cal = Calendar.getInstance(TimeZone.getDefault()); |
23 | Calendar cal = Calendar.getInstance(TimeZone.getDefault()); |
| 24 | String DATE_FORMAT = format; |
24 | String DATE_FORMAT = format; |
| 25 | java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT); |
25 | java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT); |
| 26 | /* on some JDKs, the default TimeZone is wrong |
26 | /* on some JDKs, the default TimeZone is wrong |
| 27 | * we must set the TimeZone manually |
27 | * we must set the TimeZone manually |
| 28 | * sdf.setTimeZone(TimeZone.getTimeZone("EST")); |
28 | * sdf.setTimeZone(TimeZone.getTimeZone("EST")); |
| 29 | */ |
29 | */ |
| 30 | sdf.setTimeZone(TimeZone.getDefault()); |
30 | sdf.setTimeZone(TimeZone.getDefault()); |
| 31 | return sdf.format(cal.getTime()); |
31 | return sdf.format(cal.getTime()); |
| 32 | } |
32 | } |
| 33 | 33 | ||
| 34 | /** |
34 | /** |
| 35 | * Gets current date and time formatted as a string using |
35 | * Gets current date and time formatted as a string using |
| 36 | * the format "yyyy-MM-dd HH:mm:ss". |
36 | * the format "yyyy-MM-dd HH:mm:ss". |
| 37 | * @return Current date and time as a string. |
37 | * @return Current date and time as a string. |
| 38 | */ |
38 | */ |
| 39 | public static String now() { |
39 | public static String now() { |
| 40 | return now("yyyy-MM-dd HH:mm:ss"); |
40 | return now("yyyy-MM-dd HH:mm:ss"); |
| 41 | } |
41 | } |
| 42 | 42 | ||
| 43 | } |
43 | } |
| 44 | 44 | ||