KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > RFC1123


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.util;
11
12 import java.util.*;
13 import java.text.*;
14 import org.mmbase.util.logging.*;
15
16 /**
17  * Class with support for creation of date strings in GMT format.
18  * Date strings in this format are used in http headers.
19  *
20  */

21 public class RFC1123 {
22
23     //logger
24
static Logger log = Logging.getLoggerInstance(RFC1123.class.getName());
25
26
27     private static DateFormat formatter;
28
29     static {
30         formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
31         formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
32     }
33
34     /**
35      * Abbreviated names of week days
36      * @deprecated
37      */

38     private static String JavaDoc days[]={ "Sun, ","Mon, ","Tue, ","Wed, ","Thu, ","Fri, ","Sat, ","Sun, " };
39
40     /**
41      * Create a date string in GMT format.
42      * Uses basic date functionality
43      * @deprecated use {@link #makeDate} instead
44      */

45     public static String JavaDoc makeDateV1(Date d) {
46         return days[d.getDay()]+d.toGMTString();
47     }
48     /**
49      * Create a date string in GMT format.
50      * @deprecated use {@link #makeDate} instead
51      */

52     public static String JavaDoc makeDateV2(Date d) {
53         return makeDate(d);
54     }
55
56     /**
57      * Create a date string in GMT format.
58      */

59     public static String JavaDoc makeDate(Date d) {
60         return formatter.format(d);
61     }
62
63     
64     /**
65      * Method to call this class from the commandline for testing.
66      */

67     public static void main(String JavaDoc args[]) {
68         log.info("Date "+makeDateV1(new Date()));
69         log.info("Date "+makeDateV2(new Date()));
70         log.info("Date(corr) "+makeDateV1(new Date(DateSupport.currentTimeMillis())));
71         log.info("Date(corr) "+makeDateV2(new Date(DateSupport.currentTimeMillis())));
72     }
73
74 }
75
Popular Tags