001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.log4j.helpers; 019 020import java.util.Date; 021import java.text.FieldPosition; 022import java.text.ParsePosition; 023import java.text.DateFormat; 024 025/** 026 Formats a {@link Date} by printing the number of milliseconds 027 elapsed since construction of the format. This is the fastest 028 printing DateFormat in the package. 029 030 @author Ceki Gülcü 031 032 @since 0.7.5 033*/ 034public class RelativeTimeDateFormat extends DateFormat { 035 private static final long serialVersionUID = 7055751607085611984L; 036 037 038 protected final long startTime; 039 040 public 041 RelativeTimeDateFormat() { 042 this.startTime = System.currentTimeMillis(); 043 } 044 045 /** 046 Appends to <code>sbuf</code> the number of milliseconds elapsed 047 since the start of the application. 048 049 @since 0.7.5 050 */ 051 public 052 StringBuffer format(Date date, StringBuffer sbuf, 053 FieldPosition fieldPosition) { 054 //System.err.println(":"+ date.getTime() + " - " + startTime); 055 return sbuf.append((date.getTime() - startTime)); 056 } 057 058 /** 059 This method does not do anything but return <code>null</code>. 060 */ 061 public 062 Date parse(java.lang.String s, ParsePosition pos) { 063 return null; 064 } 065}