Commit 355f14f2 authored by Quxl's avatar Quxl

x

parent 2be3148e
...@@ -7,61 +7,52 @@ import java.util.Date; ...@@ -7,61 +7,52 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.egolm.sso.config.XRException;
public class DateUtil { public class DateUtil {
private static Map<String, DateFormat> fmtMap = new HashMap<>(); private static Map<String, DateFormat> fmtMap = new HashMap<>();
public static final String FMT_DATE = "yyyyMMdd"; public static final String FMT_DATE = "yyyyMMdd";
public static final String FMT_TIME = "HHmmss"; public static final String FMT_TIME = "HHmmss";
public static final String FMT_DATE_TIME = "yyyy-MM-dd HH:mm:ss"; public static final String FMT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
public static final String FMT_DATETIME = "yyyyMMddHHmmss"; public static final String FMT_DATETIME = "yyyyMMddHHmmss";
public static String formatDate(Date date, String fmt) {
public static String formatDate(Date d, String fmt) {
DateFormat df = getFmt(fmt);
return formatDate(d, df);
}
public static String formatDate(Date d, DateFormat fmt) {
return fmt.format(d);
}
public static Date parseDate(String d, String fmt) {
DateFormat df = getFmt(fmt); DateFormat df = getFmt(fmt);
return parseDate(d, df); return formatDate(date, df);
} }
public static Date parseDate(String d, DateFormat fmt) { public static String formatDate(Date date, DateFormat fmt) {
try { return fmt.format(date);
return fmt.parse(d);
} catch (ParseException e) {
throw new RuntimeException(d + " parse to" + fmt, e);
}
} }
public static Date parseDateNoEmpty(String d, String fmt) { public static Object parseDate(String dateString, String fmt) {
Date res; if ("00000000".equals(dateString)) {
if(d!=null&&!d.equals("")) { return "0000-00-00";
res = parseDate(d, fmt); } else {
}else { try {
res = new Date(0); DateFormat df = getFmt(fmt);
return df.parse(dateString);
} catch (ParseException e) {
throw new XRException(e);
}
} }
return res;
} }
public static Date parseDateNoEmpty(String d, DateFormat fmt) { public static Object parseDateNoEmpty(String dateString, String fmt) {
Date res; Object res;
if(d!=null&&!d.equals("")) { if (dateString != null && !dateString.equals("")) {
res = parseDate(d, fmt); res = parseDate(dateString, fmt);
}else { } else {
res = new Date(0); res = new Date(0);
} }
return res; return res;
} }
public static DateFormat getFmt(String fmt) { public static DateFormat getFmt(String fmt) {
DateFormat df = fmtMap.get(fmt); DateFormat df = fmtMap.get(fmt);
if(df == null) { if (df == null) {
df = new SimpleDateFormat(fmt); df = new SimpleDateFormat(fmt);
fmtMap.put(fmt, df); fmtMap.put(fmt, df);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment