1 2 23 package com.geinuke.common; 24 25 import java.util.Date ; 26 import java.util.GregorianCalendar ; 27 import java.util.Locale ; 28 29 import org.apache.velocity.tools.generic.DateTool; 30 31 32 public class PageTool { 33 protected Locale locale=null; 34 protected DateTool dt=null; 35 36 public PageTool(){ 37 dt=new DateTool(); 38 } 39 40 public PageTool(Locale lo){ 41 dt=new DateTool(); 42 this.locale=lo; 43 } 44 45 public String formatDate(GregorianCalendar gc){ 46 String text=null; 47 if(this.locale!=null) 48 text=this.dt.format(dt.getFormat(),gc,this.locale); 49 else 50 text=this.dt.format(dt.getFormat(),gc); 51 return text; 52 } 53 54 public String formatDate(long time){ 55 GregorianCalendar gc=null; 56 Date d=new Date (time); 57 gc=new GregorianCalendar (); 58 gc.setTime(d); 59 String text=null; 60 if(this.locale!=null) 61 text=this.dt.format(dt.getFormat(),gc,this.locale); 62 else 63 text=this.dt.format(dt.getFormat(),gc); 64 return text; 65 } 66 67 public String formatDate(String s,GregorianCalendar gc){ 68 String text=null; 69 if(this.locale!=null) 70 text=this.dt.format(s,gc,this.locale); 71 else 72 text=this.dt.format(s,gc); 73 return text; 74 } 75 76 public Locale getLocale() { 77 return locale; 78 } 79 public void setLocale(Locale locale) { 80 this.locale = locale; 81 } 82 } 83 | Popular Tags |