commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryce Fischer <br...@berzerker-soft.com>
Subject Re: BeanUtils: Convert Date to String
Date Thu, 19 Aug 2004 02:56:46 GMT
Well.. I'm answering my own question. I guess I needed to create my own 
StringConverter class:

public class MyStringConverter implements Converter {
   private static DateFormat df = new SimpleDateFormat("yyyy.MM.dd");

   public Object convert(Class type, Object value) {
      Object returnObj = null;
      if (value != null) {
         if (value instanceof Date){
            returnObj = df.format((Date)value);
         } else {
            returnObj = value.toString();
         }
      }
     
      return returnObj;
   }
}

Then I just registered the above class:
ConvertUtils.register(new MyStringConverter(), String.class);

Hope this can help someone else who encounters the same thing.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message