import org.apache.commons.lang3.StringUtils;
import java.sql.Date;
import java.text.SimpleDateFormat;
public class DateUtils {
public static Date stringToSqlDate(String time) throws Exception {
if(StringUtils.isNotBlank(time)) {
Date date = Date.valueOf(time);
return date;
}else{
return null;
}
}
public static java.util.Date stringToUtilDate(String time) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(StringUtils.isNotBlank(time)) {
java.util.Date date = sdf.parse(time);
return date;
}else{
return null;
}
}
public static String stringUtilDateToUtilDate(String time) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(StringUtils.isNotBlank(time)) {
java.util.Date date = sdf.parse(time);
return sdf.format(date);
}else{
return null;
}
}
public static String objectUtilDateToString(Object objTime) throws Exception {
String time = objTime + "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(StringUtils.isNotBlank(time)) {
java.util.Date date = sdf.parse(time);
return sdf.format(date);
}else{
return null;
}
}
}