From 2b1f7a47394363e95deb4dfa0f1c67d41e747f7f Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 01 二月 2023 10:56:40 +0800
Subject: [PATCH] Merge branch 'wvp-28181-2.0' into fix-269

---
 src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java |   90 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java
new file mode 100644
index 0000000..f7e0729
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java
@@ -0,0 +1,90 @@
+package com.genersoft.iot.vmp.utils;
+
+
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
+import java.time.temporal.TemporalAccessor;
+
+import java.util.Locale;
+
+/**    
+ * 鍏ㄥ眬鏃堕棿宸ュ叿绫�
+ * @author lin
+ */
+public class DateUtil {
+
+    /**
+     * 鍏煎涓嶈鑼冪殑iso8601鏃堕棿鏍煎紡
+     */
+	private static final String ISO8601_COMPATIBLE_PATTERN = "yyyy-M-d'T'H:m:s";
+
+    /**
+     * 鐢ㄤ互杈撳嚭鏍囧噯鐨刬so8601鏃堕棿鏍煎紡
+     */
+	private static final String ISO8601_PATTERN = "yyyy-MM-dd'T'HH:mm:ss";
+
+    /**
+     * wvp鍐呴儴缁熶竴鏃堕棿鏍煎紡
+     */
+    public static final String PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+    public static final String zoneStr = "Asia/Shanghai";
+
+    public static final DateTimeFormatter formatterCompatibleISO8601 = DateTimeFormatter.ofPattern(ISO8601_COMPATIBLE_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr));
+    public static final DateTimeFormatter formatterISO8601 = DateTimeFormatter.ofPattern(ISO8601_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr));
+    public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr));
+
+	public static String yyyy_MM_dd_HH_mm_ssToISO8601(String formatTime) {
+
+        return formatterISO8601.format(formatter.parse(formatTime));
+    }
+	
+	public static String ISO8601Toyyyy_MM_dd_HH_mm_ss(String formatTime) {
+        return formatter.format(formatterCompatibleISO8601.parse(formatTime));
+
+    }
+
+    /**
+     * yyyy_MM_dd_HH_mm_ss 杞椂闂存埑
+     * @param formatTime
+     * @return
+     */
+	public static long yyyy_MM_dd_HH_mm_ssToTimestamp(String formatTime) {
+        TemporalAccessor temporalAccessor = formatter.parse(formatTime);
+        Instant instant = Instant.from(temporalAccessor);
+        return instant.getEpochSecond();
+	}
+
+    /**
+     * 鑾峰彇褰撳墠鏃堕棿
+     * @return
+     */
+    public static String getNow() {
+        LocalDateTime nowDateTime = LocalDateTime.now();
+        return formatter.format(nowDateTime);
+    }
+
+    /**
+     * 鏍煎紡鏍¢獙
+     * @param timeStr 鏃堕棿瀛楃涓�
+     * @param dateTimeFormatter 寰呮牎楠岀殑鏍煎紡
+     * @return
+     */
+    public static boolean verification(String timeStr, DateTimeFormatter dateTimeFormatter) {
+        try {
+            LocalDate.parse(timeStr, dateTimeFormatter);
+            return true;
+        }catch (DateTimeParseException exception) {
+            return false;
+        }
+    }
+
+    public static String getNowForISO8601() {
+        LocalDateTime nowDateTime = LocalDateTime.now();
+        return formatterISO8601.format(nowDateTime);
+    }
+}

--
Gitblit v1.8.0