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.Date;
21 import java.text.FieldPosition;
22 import java.text.ParsePosition;
23 import java.text.DateFormat;
24
25 /***
26 Formats a {@link Date} by printing the number of milliseconds
27 elapsed since construction of the format. This is the fastest
28 printing DateFormat in the package.
29
30 @author Ceki Gülcü
31
32 @since 0.7.5
33 */
34 public class RelativeTimeDateFormat extends DateFormat {
35 private static final long serialVersionUID = 7055751607085611984L;
36
37
38 protected final long startTime;
39
40 public
41 RelativeTimeDateFormat() {
42 this.startTime = System.currentTimeMillis();
43 }
44
45 /***
46 Appends to <code>sbuf</code> the number of milliseconds elapsed
47 since the start of the application.
48
49 @since 0.7.5
50 */
51 public
52 StringBuffer format(Date date, StringBuffer sbuf,
53 FieldPosition fieldPosition) {
54
55 return sbuf.append((date.getTime() - startTime));
56 }
57
58 /***
59 This method does not do anything but return <code>null</code>.
60 */
61 public
62 Date parse(java.lang.String s, ParsePosition pos) {
63 return null;
64 }
65 }