FileDocCategorySizeDatePackage
AbsoluteTimeDateFormat.javaAPI DocApache log4j 1.2.154015Sat Aug 25 00:09:40 BST 2007org.apache.log4j.helpers

AbsoluteTimeDateFormat

public class AbsoluteTimeDateFormat extends DateFormat
Formats a {@link Date} in the format "HH:mm:ss,SSS" for example, "15:49:37,459".
author
Ceki Gülcü
author
Andrew Vajoczki
since
0.7.5

Fields Summary
private static final long
serialVersionUID
public static final String
ABS_TIME_DATE_FORMAT
String constant used to specify {@link org.apache.log4j.helpers.AbsoluteTimeDateFormat} in layouts. Current value is ABSOLUTE.
public static final String
DATE_AND_TIME_DATE_FORMAT
String constant used to specify {@link org.apache.log4j.helpers.DateTimeDateFormat} in layouts. Current value is DATE.
public static final String
ISO8601_DATE_FORMAT
String constant used to specify {@link org.apache.log4j.helpers.ISO8601DateFormat} in layouts. Current value is ISO8601.
private static long
previousTime
private static char[]
previousTimeWithoutMillis
Constructors Summary
public AbsoluteTimeDateFormat()


  
   
    setCalendar(Calendar.getInstance());
  
public AbsoluteTimeDateFormat(TimeZone timeZone)

    setCalendar(Calendar.getInstance(timeZone));
  
Methods Summary
public java.lang.StringBufferformat(java.util.Date date, java.lang.StringBuffer sbuf, java.text.FieldPosition fieldPosition)
Appends to sbuf the time in the format "HH:mm:ss,SSS" for example, "15:49:37,459"

param
date the date to format
param
sbuf the string buffer to write to
param
fieldPosition remains untouched

 // "HH:mm:ss."

                                                        
  
      
		        

    long now = date.getTime();
    int millis = (int)(now % 1000);

    if ((now - millis) != previousTime) {
      // We reach this point at most once per second
      // across all threads instead of each time format()
      // is called. This saves considerable CPU time.

      calendar.setTime(date);

      int start = sbuf.length();
      
      int hour = calendar.get(Calendar.HOUR_OF_DAY);
      if(hour < 10) {
	sbuf.append('0");
      }
      sbuf.append(hour);
      sbuf.append(':");
      
      int mins = calendar.get(Calendar.MINUTE);
      if(mins < 10) {
	sbuf.append('0");
      }
      sbuf.append(mins);
      sbuf.append(':");
      
      int secs = calendar.get(Calendar.SECOND);
      if(secs < 10) {
	sbuf.append('0");
      }
      sbuf.append(secs);
      sbuf.append(',");      

      // store the time string for next time to avoid recomputation
      sbuf.getChars(start, sbuf.length(), previousTimeWithoutMillis, 0);
      
      previousTime = now - millis;
    }
    else {
      sbuf.append(previousTimeWithoutMillis);
    }
    

    
    if(millis < 100) 
      sbuf.append('0");
    if(millis < 10) 
      sbuf.append('0");
    
    sbuf.append(millis);
    return sbuf;
  
public java.util.Dateparse(java.lang.String s, java.text.ParsePosition pos)
This method does not do anything but return null.

    return null;