KickJava   Java API By Example, From Geeks To Geeks.

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


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.Date JavaDoc;
20 import java.text.FieldPosition JavaDoc;
21 import java.text.ParsePosition JavaDoc;
22 import java.text.DateFormat JavaDoc;
23
24 /**
25    Formats a {@link Date} by printing the number of milliseconds
26    elapsed since the start of the application. This is the fastest
27    printing DateFormat in the package.
28    
29    @author Ceki Gülcü
30    
31    @since 0.7.5
32 */

33 public class RelativeTimeDateFormat extends DateFormat JavaDoc {
34
35   protected final long startTime;
36
37   public
38   RelativeTimeDateFormat() {
39     this.startTime = System.currentTimeMillis();
40   }
41   
42   /**
43      Appends to <code>sbuf</code> the number of milliseconds elapsed
44      since the start of the application.
45      
46      @since 0.7.5
47   */

48   public
49   StringBuffer JavaDoc format(Date JavaDoc date, StringBuffer JavaDoc sbuf,
50               FieldPosition JavaDoc fieldPosition) {
51     //System.err.println(":"+ date.getTime() + " - " + startTime);
52
return sbuf.append((date.getTime() - startTime));
53   }
54
55   /**
56      This method does not do anything but return <code>null</code>.
57    */

58   public
59   Date JavaDoc parse(java.lang.String JavaDoc s, ParsePosition JavaDoc pos) {
60     return null;
61   }
62 }
63
Popular Tags