1 5 package com.opensymphony.webwork.util; 6 7 import java.text.DateFormat ; 8 import java.text.ParseException ; 9 import java.text.SimpleDateFormat ; 10 import java.util.Date ; 11 12 13 19 public class DateFormatter { 20 22 Date date; 23 DateFormat format; 24 25 DateFormat parser; 27 28 30 public DateFormatter() { 32 this.parser = new SimpleDateFormat (); 33 this.format = new SimpleDateFormat (); 34 this.date = new Date (); 35 } 36 37 39 public void setDate(String date) { 40 try { 41 this.date = parser.parse(date); 42 } catch (ParseException e) { 43 throw new IllegalArgumentException (e.getMessage()); 44 } 45 } 46 47 public void setDate(Date date) { 48 this.date = date; 49 } 50 51 public void setDate(int date) { 52 setDate(Integer.toString(date)); 53 } 54 55 public Date getDate() { 56 return this.date; 57 } 58 59 public void setFormat(String format) { 60 this.format = new SimpleDateFormat (format); 61 } 62 63 public void setFormat(DateFormat format) { 64 this.format = format; 65 } 66 67 public String getFormattedDate() { 68 return format.format(date); 69 } 70 71 public void setParseFormat(String format) { 72 this.parser = new SimpleDateFormat (format); 73 } 74 75 public void setParser(DateFormat parser) { 76 this.parser = parser; 77 } 78 79 public void setTime(long time) { 80 date.setTime(time); 81 } 82 } 83 | Popular Tags |