From 66529cc3a031df6c458eedc4276e9b65c3b8dfd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=90=A6=E6=B6=9B?= Date: Thu, 9 Mar 2023 12:02:23 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=20sonar=E3=80=91DateUtils=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jero/common/util/DateUtils.java | 49 +++---------------- 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/DateUtils.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/DateUtils.java index 8076967f..99e79cb2 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/DateUtils.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/util/DateUtils.java @@ -26,48 +26,13 @@ import org.springframework.util.StringUtils; */ public class DateUtils extends PropertyEditorSupport { - public static ThreadLocal date_sdf = new ThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("yyyy-MM-dd"); - } - }; - public static ThreadLocal yyyyMMdd = new ThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("yyyyMMdd"); - } - }; - public static ThreadLocal date_sdf_wz = new ThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("yyyy年MM月dd日"); - } - }; - public static ThreadLocal time_sdf = new ThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("yyyy-MM-dd HH:mm"); - } - }; - public static ThreadLocal yyyymmddhhmmss = new ThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("yyyyMMddHHmmss"); - } - }; - public static ThreadLocal short_time_sdf = new ThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("HH:mm"); - } - }; - public static ThreadLocal datetimeFormat = new ThreadLocal() { - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - } - }; + public static ThreadLocal date_sdf = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd")); + public static ThreadLocal yyyyMMdd = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMMdd")); + public static ThreadLocal date_sdf_wz = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy年MM月dd日")); + public static ThreadLocal time_sdf = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm")); + public static ThreadLocal yyyymmddhhmmss = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMMddHHmmss")); + public static ThreadLocal short_time_sdf = ThreadLocal.withInitial(() -> new SimpleDateFormat("HH:mm")); + public static ThreadLocal datetimeFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); // 以毫秒表示的时间 private static final long DAY_IN_MILLIS = 24 * 3600 * 1000L;