shilin 1 год назад
Родитель
Сommit
d01a9000a4

+ 9 - 17
web/runeconomy-xk/src/main/java/com/gyee/runeconomy/util/DateUtils.java

@@ -21,53 +21,45 @@ public class DateUtils {
 
     // 获取线程的变量副本,如果不覆盖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 =new SimpleDateFormat();
+        SimpleDateFormat df = (SimpleDateFormat) threadLocal.get();
 
         if (df == null) {
             df = new SimpleDateFormat(format);
-
+            threadLocal.set(df);
         }
-
+        df.setLenient(false);
         return df;
 
     }
 
     public static SimpleDateFormat getFormat1() {
 
-        SimpleDateFormat df1 = new SimpleDateFormat();
+        SimpleDateFormat df1 = (SimpleDateFormat) threadLocal.get();
 
         if (df1 == null) {
             df1 = new SimpleDateFormat(format1);
-
+            threadLocal.set(df1);
         }
-
+        df1.setLenient(false);
         return df1;
 
     }
 
     public static SimpleDateFormat getFormat2() {
 
-        SimpleDateFormat df2 = new SimpleDateFormat();
+        SimpleDateFormat df2 = (SimpleDateFormat) threadLocal.get();
 
         if (df2 == null) {
             df2 = new SimpleDateFormat(format2);
-
+            threadLocal.set(df2);
         }
-
+        df2.setLenient(false);
         return df2;
 
     }
 
-
     public static Date pareDateNoHours(String date) {
 
         SimpleDateFormat df2 = new SimpleDateFormat(format);