01: /******************************************************************************
02: * DateUtils.java
03: * ****************************************************************************/package org.openlaszlo.utils;
04:
05: import java.text.SimpleDateFormat;
06: import java.text.ParseException;
07: import java.util.Date;
08:
09: import org.openlaszlo.utils.ChainedException;
10:
11: /**
12: * Utility class for dates
13: */
14: public class DateUtils {
15:
16: /**
17: * Return a formatter
18: */
19: private static SimpleDateFormat getFormatter() {
20: return new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
21: }
22:
23: /**
24: * Convert a long to a Date String
25: */
26: public static String getDateString(long d) {
27: return getFormatter().format(new Date(d));
28: }
29:
30: /**
31: * Convert a date String to a long
32: */
33: public static long getDate(String s) {
34: try {
35: return getFormatter().parse(s).getTime();
36: } catch (java.text.ParseException e) {
37: throw new ChainedException(e);
38: }
39: }
40: }
|