1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.helpers;
19
20 import java.util.Calendar;
21 import java.util.TimeZone;
22 import java.util.Date;
23 import java.text.FieldPosition;
24 import java.text.ParsePosition;
25 import java.text.DateFormatSymbols;
26
27 /***
28 Formats a {@link Date} in the format "dd MMM yyyy HH:mm:ss,SSS" for example,
29 "06 Nov 1994 15:49:37,459".
30
31 @author Ceki Gülcü
32 @since 0.7.5
33 */
34 public class DateTimeDateFormat extends AbsoluteTimeDateFormat {
35 private static final long serialVersionUID = 5547637772208514971L;
36
37 String[] shortMonths;
38
39 public
40 DateTimeDateFormat() {
41 super();
42 shortMonths = new DateFormatSymbols().getShortMonths();
43 }
44
45 public
46 DateTimeDateFormat(TimeZone timeZone) {
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
58 StringBuffer format(Date date, StringBuffer sbuf,
59 FieldPosition fieldPosition) {
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
82 Date parse(java.lang.String s, ParsePosition pos) {
83 return null;
84 }
85 }