|
@@ -25,13 +25,21 @@ public class DateUtils {
|
|
|
private static final String format1 = "yyyy-MM-dd HH:mm:ss";
|
|
|
private static final String format2 = "MM/dd/yyyy HH:mm:ss";
|
|
|
private static final String format3 = "yyyy-MM";
|
|
|
+ public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
|
|
+ public final static String DATE_PATTERN = "yyyy-MM-dd";
|
|
|
|
|
|
// 第一次调用get将返回null
|
|
|
|
|
|
private static ThreadLocal<SimpleDateFormat> threadLocal = new ThreadLocal<SimpleDateFormat>();
|
|
|
|
|
|
// 获取线程的变量副本,如果不覆盖initialValue,第一次get返回null,故需要初始化一个SimpleDateFormat,并set到threadLocal中
|
|
|
-
|
|
|
+ public static String format(Date date, String pattern) {
|
|
|
+ if (date != null) {
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat(pattern);
|
|
|
+ return df.format(date);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
public static SimpleDateFormat getFormat() {
|
|
|
|
|
|
SimpleDateFormat df = (SimpleDateFormat) threadLocal.get();
|