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 }