public static final String pattern = "yyyy-MM-dd HH:mm:ss";
public static String getTime(Date date){
return date != null ? formatDate(date,pattern): null;
}
public static Date getTime(String date) {
return date != null && date != "" ? parse(date,pattern) : null;
}
public static Date parse(String date,String pattern){
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
try {
return sdf.parse(date);
}catch(ParseException e) {
log.error(e);
return null;
}
}
public static String formatDate(Date date,String pattern){
if (date == null){
return "";
}
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
}
评论区