All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sghd.common.utils.converter.StringToDateConverter Maven / Gradle / Ivy

The newest version!
package com.sghd.common.utils.converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;

/**
 * 字符串到日期对象的转换器
 * 
 * @author frank
 */
public class StringToDateConverter implements Converter {

	@Override
	public Date convert(String source) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			return df.parse(source);
		} catch (ParseException e) {
			throw new IllegalArgumentException("字符串[" + source + "]不符合格式要求[yyyy-MM-dd HH:mm:ss]", e);
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy