KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > logging > jdk > format > 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.jboss.logging.jdk.format;
18
19 import java.text.DateFormatSymbols JavaDoc;
20 import java.text.FieldPosition JavaDoc;
21 import java.text.ParsePosition JavaDoc;
22 import java.util.TimeZone JavaDoc;
23 import java.util.Calendar JavaDoc;
24 import java.util.Date 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  * @author Scott.Stark@jboss.org
32  * @version $Revision: 1958 $
33  */

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

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

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