1 16 package org.jboss.logging.jdk.format; 17 18 import java.text.DateFormat ; 19 import java.text.FieldPosition ; 20 import java.text.ParsePosition ; 21 import java.util.Calendar ; 22 import java.util.TimeZone ; 23 import java.util.Date ; 24 25 34 public class AbsoluteTimeDateFormat extends DateFormat 35 { 36 37 42 public final static String ABS_TIME_DATE_FORMAT = "ABSOLUTE"; 43 44 49 public final static String DATE_AND_TIME_DATE_FORMAT = "DATE"; 50 51 56 public final static String ISO8601_DATE_FORMAT = "ISO8601"; 57 58 public AbsoluteTimeDateFormat() 59 { 60 setCalendar(Calendar.getInstance()); 61 } 62 63 public AbsoluteTimeDateFormat(TimeZone timeZone) 64 { 65 setCalendar(Calendar.getInstance(timeZone)); 66 } 67 68 private static long previousTime; 69 private static char[] previousTimeWithoutMillis = new char[9]; 71 79 public StringBuffer format(Date date, StringBuffer sbuf, 80 FieldPosition fieldPosition) 81 { 82 83 long now = date.getTime(); 84 int millis = (int) (now % 1000); 85 86 if ((now - millis) != previousTime) 87 { 88 92 calendar.setTime(date); 93 94 int start = sbuf.length(); 95 96 int hour = calendar.get(Calendar.HOUR_OF_DAY); 97 if (hour < 10) 98 { 99 sbuf.append('0'); 100 } 101 sbuf.append(hour); 102 sbuf.append(':'); 103 104 int mins = calendar.get(Calendar.MINUTE); 105 if (mins < 10) 106 { 107 sbuf.append('0'); 108 } 109 sbuf.append(mins); 110 sbuf.append(':'); 111 112 int secs = calendar.get(Calendar.SECOND); 113 if (secs < 10) 114 { 115 sbuf.append('0'); 116 } 117 sbuf.append(secs); 118 sbuf.append(','); 119 120 sbuf.getChars(start, sbuf.length(), previousTimeWithoutMillis, 0); 122 123 previousTime = now - millis; 124 } 125 else 126 { 127 sbuf.append(previousTimeWithoutMillis); 128 } 129 130 131 if (millis < 100) 132 sbuf.append('0'); 133 if (millis < 10) 134 sbuf.append('0'); 135 136 sbuf.append(millis); 137 return sbuf; 138 } 139 140 143 public Date parse(String s, ParsePosition pos) 144 { 145 return null; 146 } 147 } 148 | Popular Tags |