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