1 37 package net.sourceforge.cruisecontrol.util; 38 39 import java.text.DateFormat ; 40 import java.text.FieldPosition ; 41 import java.text.NumberFormat ; 42 import java.text.ParsePosition ; 43 import java.text.SimpleDateFormat ; 44 import java.util.Date ; 45 import java.util.TimeZone ; 46 47 54 public final class TimeNumberFormat extends NumberFormat { 55 private static final String UTC_TIME_ZONE = "+0:00"; 56 private static final String HOURS_MINUTE = "HH:mm"; 57 58 private final DateFormat realFormat; 59 60 61 public TimeNumberFormat() { 62 SimpleDateFormat format = new SimpleDateFormat (HOURS_MINUTE); 63 format.setTimeZone(TimeZone.getTimeZone(UTC_TIME_ZONE)); 64 realFormat = format; 65 } 66 67 68 public StringBuffer format(double arg0, StringBuffer arg1, 69 FieldPosition arg2) { 70 return realFormat.format(new Date ((long) arg0), arg1, arg2); 71 } 72 73 74 public StringBuffer format(long arg0, StringBuffer arg1, 75 FieldPosition arg2) { 76 return realFormat.format(new Date (arg0), arg1, arg2); 77 } 78 79 80 public Number parse(String arg0, ParsePosition arg1) { 81 return new Long (realFormat.parse(arg0, arg1).getTime()); 82 } 83 } | Popular Tags |