1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 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 //System.err.println(":"+ date.getTime() + " - " + startTime); 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 }