public class DateUtil {
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
public static final String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
public static Date strToDate(String str, String dateFormat) {
if(StringUtils.isBlank(str)){
return null;
}
try {
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
return format.parse(str);
} catch (ParseException e) {
return null;
}
}
public static String dateToStr(Date date, String dateFormat) {
if(date==null){
return null;
}
try {
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
String str = format.format(date);
return str;
}catch (Exception e){
return null;
}
}
public static String strToStr(String str, String dateFormatOri, String dateFormatDes) {
if (StringUtils.isBlank(dateFormatOri) || StringUtils.isBlank(dateFormatDes)) {
return null;
}
return dateToStr(strToDate(str, dateFormatOri), dateFormatDes);
}
}