KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > helpers > DateTimeDateFormat


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.log4j.helpers;
18
19 import java.util.Calendar JavaDoc;
20 import java.util.TimeZone JavaDoc;
21 import java.util.Date JavaDoc;
22 import java.text.FieldPosition JavaDoc;
23 import java.text.ParsePosition JavaDoc;
24 import java.text.DateFormatSymbols JavaDoc;
25
26 /**
27    Formats a {@link Date} in the format "dd MMM YYYY HH:mm:ss,SSS" for example,
28    "06 Nov 1994 15:49:37,459".
29
30    @author Ceki Gülcü
31    @since 0.7.5
32 */

33 public class DateTimeDateFormat extends AbsoluteTimeDateFormat {
34
35   String JavaDoc[] shortMonths;
36
37   public
38   DateTimeDateFormat() {
39     super();
40     shortMonths = new DateFormatSymbols JavaDoc().getShortMonths();
41   }
42
43   public
44   DateTimeDateFormat(TimeZone JavaDoc timeZone) {
45     this();
46     setCalendar(Calendar.getInstance(timeZone));
47   }
48
49   /**
50      Appends to <code>sbuf</code> the date in the format "dd MMM YYYY
51      HH:mm:ss,SSS" for example, "06 Nov 1994 08:49:37,459".
52
53      @param sbuf the string buffer to write to
54   */

55   public
56   StringBuffer JavaDoc format(Date JavaDoc date, StringBuffer JavaDoc sbuf,
57               FieldPosition JavaDoc fieldPosition) {
58
59     calendar.setTime(date);
60
61     int day = calendar.get(Calendar.DAY_OF_MONTH);
62     if(day < 10)
63       sbuf.append('0');
64     sbuf.append(day);
65     sbuf.append(' ');
66     sbuf.append(shortMonths[calendar.get(Calendar.MONTH)]);
67     sbuf.append(' ');
68
69     int year = calendar.get(Calendar.YEAR);
70     sbuf.append(year);
71     sbuf.append(' ');
72
73     return super.format(date, sbuf, fieldPosition);
74   }
75
76   /**
77      This method does not do anything but return <code>null</code>.
78    */

79   public
80   Date JavaDoc parse(java.lang.String JavaDoc s, ParsePosition JavaDoc pos) {
81     return null;
82   }
83 }
84
Popular Tags