实现Formatter接口
程序员文章站
2022-03-23 23:16:57
...
package com.gem.formatter;
import org.springframework.format.Formatter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class DateFormatter implements Formatter<Date> {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@Override
public String print(Date date, Locale locale) {
return sdf.format(date);
}
@Override
public Date parse(String s, Locale locale) throws ParseException {
return sdf.parse(s);
}
}