fengxiang
2018-04-25 fb35e34d8627cdecfd084909258aa4b50012ce57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.moral.common.convert;
 
import com.moral.common.util.StringUtils;
import org.springframework.core.convert.converter.Converter;
 
import java.util.Date;
 
/**
 * 字符串转日期的转换器
 * @author byshome
 * @version $Id: StringToDateConverter.java, v 0.1 2015年9月24日 下午7:19:41 byshome Exp $
 */
public class StringToDateConverter implements Converter<String, Date> {
//    private static final String dateFormat      = "yyyy-MM-dd HH:mm:ss";
//    private static final String shortDateFormat = "yyyy-MM-dd";
 
    /** 
     * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
     */
    @Override
    public Date convert(String source) {
          if(StringUtils.isNullOrEmpty(source)){
              throw new RuntimeException(String.format("parser %s to Date fail", source));
          };
          return  new Date(Long.parseLong(source.substring(0,source.length()-3)+"000"));
    }
 
}