一、实现日期格式数据类型的转换

首先,定义DateConverter实现Converter<String, Date>接口:

 1 package com.stevlu.common;
 2 
 3 import org.springframework.core.convert.converter.Converter;
 4 
 5 import java.text.ParseException;
 6 import java.text.SimpleDateFormat;
 7 import java.util.Date;
 8 
 9 /**
10  * Created by Steven Lu on 2018/11/21.
11  */
12 public class DateConverter implements Converter<String, Date> {
13     private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
14 
15     @Override
16     public Date convert(String s) {
17         if ("".equals(s) || s == null) {
18             return null;
19         }
20         try {
21             return simpleDateFormat.parse(s);
22         } catch (ParseException e) {
23             e.printStackTrace();
24         }
25         return null;
26     }
27 }
View Code

相关文章:

  • 2021-07-31
  • 2021-10-12
  • 2022-12-23
  • 2021-11-12
  • 2021-09-12
  • 2021-09-04
  • 2021-11-08
猜你喜欢
  • 2021-09-01
  • 2021-10-05
  • 2022-12-23
  • 2022-01-07
  • 2022-02-10
  • 2021-12-03
  • 2021-09-16
相关资源
相似解决方案