package com.Keafmd.utils;
import org.springframework.core.convert.converter.Converter;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;http://yezishuju.com/
/**
-
Keafmd
-
@ClassName: StringToDateConverter
-
@Description: 把字符串转换成日期的转换器
-
@author: 牛哄哄的柯南
-
@date: 2021-01-24 19:27
*/
public class StringToDateConverter implements Converter<String,Date> {@Override
public Date convert(String s) {
if(s==null){
throw new RuntimeException(“请传入数据”);
}
DateFormat dateFormat = new SimpleDateFormat(“yyyy-MM-dd”);try { //把字符串转为日期 return dateFormat.parse(s); } catch (ParseException e) { throw new RuntimeException("数据类型转换错误"); }
}
}