KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > utils > DateUtils


1 /******************************************************************************
2  * DateUtils.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.utils;
11
12 import java.text.SimpleDateFormat JavaDoc;
13 import java.text.ParseException JavaDoc;
14 import java.util.Date JavaDoc;
15
16 import org.openlaszlo.utils.ChainedException;
17
18 /**
19  * Utility class for dates
20  */

21 public class DateUtils {
22
23     /**
24      * Return a formatter
25      */

26     private static SimpleDateFormat JavaDoc getFormatter() {
27         return new SimpleDateFormat JavaDoc("EEE, dd MMM yyyy HH:mm:ss z");
28     }
29
30     /**
31      * Convert a long to a Date String
32      */

33     public static String JavaDoc getDateString(long d) {
34         return getFormatter().format(new Date JavaDoc(d));
35     }
36
37     /**
38      * Convert a date String to a long
39      */

40     public static long getDate(String JavaDoc s) {
41         try {
42             return getFormatter().parse(s).getTime();
43         } catch (java.text.ParseException JavaDoc e) {
44             throw new ChainedException(e);
45         }
46     }
47 }
48
49
Popular Tags