DateFormats 추가

master
mjkhan21 1 year ago
parent 99242a3afc
commit 73af094530

@ -0,0 +1,30 @@
package cokr.xit.foundation.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import cokr.xit.foundation.Assert;
public class DateFormats {
private static final HashMap<String, SimpleDateFormat> dateFormats = new HashMap<>();
public String format(String pattern, Date date) {
if (date == null) return "";
return dateFormat(pattern).format(date);
}
private SimpleDateFormat dateFormat(String pattern) {
return dateFormats.computeIfAbsent(pattern, key -> new SimpleDateFormat(key));
}
public Date parse(String pattern, String str) {
if (Assert.isEmpty(str)) return null;
try {
return dateFormat(pattern).parse(str);
} catch (Exception e) {
throw Assert.runtimeException(e);
}
}
}
Loading…
Cancel
Save