beanutils日期转换器DateConvertUtils

 1 package com.javaweb.utils;
 2 
 3 import java.text.ParseException;
 4 import java.text.SimpleDateFormat;
 5 
 6 import org.apache.commons.beanutils.Converter;
 7 
 8 /**
 9  * 把String转换成java.util.Date类型的类型转换器
10  * @author Administrator
11  *
12  */
13 public class DateConvertUtils implements Converter{
14 
15     @SuppressWarnings("rawtypes")
16     public Object convert(Class type, Object value) {
17         if(value == null){
18             return null;
19         }
20         if(!(value instanceof String)){
21             return value;
22         }
23         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
24         try {
25             return sdf.parse((String)value);
26         } catch (ParseException e) {
27             throw new RuntimeException(e);
28         }
29     }
30 
31 }

 

posted @ 2017-02-07 14:43  Jonnyxu  阅读(2564)  评论(0编辑  收藏  举报