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 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM