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