日期格式互转
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author ZhangZZ
* @Create 2022-04-04 10:17
*/
public class DateMapperHMS {
public String dateToString(Date date) {
return date != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(date) : null;
}
public Date stringToDate(String date) {
try {
return date != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.parse(date) : null;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}