From 80b6cbfc9c861469146318d0b3dd5f8b8b525b8a Mon Sep 17 00:00:00 2001
From: xiejun <xiejun@vci-tech.com>
Date: 星期五, 01 十一月 2024 15:11:19 +0800
Subject: [PATCH] Revert "集成获取mdm分发通用数据格式接口集成"

---
 Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/DateTimeUtil.java |  226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 226 insertions(+), 0 deletions(-)

diff --git a/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/DateTimeUtil.java b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/DateTimeUtil.java
new file mode 100644
index 0000000..a5d9c79
--- /dev/null
+++ b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/DateTimeUtil.java
@@ -0,0 +1,226 @@
+/*
+ *      Copyright (c) 2018-2028, DreamLu All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: DreamLu 鍗㈡槬姊� (596392912@qq.com)
+ */
+package org.springblade.core.tool.utils;
+
+import java.time.*;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.Temporal;
+import java.time.temporal.TemporalAccessor;
+import java.util.Date;
+
+/**
+ * DateTime 宸ュ叿绫�
+ *
+ * @author L.cm
+ */
+public class DateTimeUtil {
+	public static final DateTimeFormatter DATETIME_FORMAT = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME);
+	public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE);
+	public static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern(DateUtil.PATTERN_TIME);
+
+	/**
+	 * 鏃ユ湡鏃堕棿鏍煎紡鍖�
+	 *
+	 * @param temporal 鏃堕棿
+	 * @return 鏍煎紡鍖栧悗鐨勬椂闂�
+	 */
+	public static String formatDateTime(TemporalAccessor temporal) {
+		return DATETIME_FORMAT.format(temporal);
+	}
+
+	/**
+	 * 鏃ユ湡鏃堕棿鏍煎紡鍖�
+	 *
+	 * @param temporal 鏃堕棿
+	 * @return 鏍煎紡鍖栧悗鐨勬椂闂�
+	 */
+	public static String formatDate(TemporalAccessor temporal) {
+		return DATE_FORMAT.format(temporal);
+	}
+
+	/**
+	 * 鏃堕棿鏍煎紡鍖�
+	 *
+	 * @param temporal 鏃堕棿
+	 * @return 鏍煎紡鍖栧悗鐨勬椂闂�
+	 */
+	public static String formatTime(TemporalAccessor temporal) {
+		return TIME_FORMAT.format(temporal);
+	}
+
+	/**
+	 * 鏃ユ湡鏍煎紡鍖�
+	 *
+	 * @param temporal 鏃堕棿
+	 * @param pattern  琛ㄨ揪寮�
+	 * @return 鏍煎紡鍖栧悗鐨勬椂闂�
+	 */
+	public static String format(TemporalAccessor temporal, String pattern) {
+		return DateTimeFormatter.ofPattern(pattern).format(temporal);
+	}
+
+	/**
+	 * 灏嗗瓧绗︿覆杞崲涓烘椂闂�
+	 *
+	 * @param dateStr 鏃堕棿瀛楃涓�
+	 * @param pattern 琛ㄨ揪寮�
+	 * @return 鏃堕棿
+	 */
+	public static LocalDateTime parseDateTime(String dateStr, String pattern) {
+		DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
+		return DateTimeUtil.parseDateTime(dateStr, formatter);
+	}
+
+	/**
+	 * 灏嗗瓧绗︿覆杞崲涓烘椂闂�
+	 *
+	 * @param dateStr   鏃堕棿瀛楃涓�
+	 * @param formatter DateTimeFormatter
+	 * @return 鏃堕棿
+	 */
+	public static LocalDateTime parseDateTime(String dateStr, DateTimeFormatter formatter) {
+		return LocalDateTime.parse(dateStr, formatter);
+	}
+
+	/**
+	 * 灏嗗瓧绗︿覆杞崲涓烘椂闂�
+	 *
+	 * @param dateStr 鏃堕棿瀛楃涓�
+	 * @return 鏃堕棿
+	 */
+	public static LocalDateTime parseDateTime(String dateStr) {
+		return DateTimeUtil.parseDateTime(dateStr, DateTimeUtil.DATETIME_FORMAT);
+	}
+
+	/**
+	 * 灏嗗瓧绗︿覆杞崲涓烘椂闂�
+	 *
+	 * @param dateStr 鏃堕棿瀛楃涓�
+	 * @param pattern 琛ㄨ揪寮�
+	 * @return 鏃堕棿
+	 */
+	public static LocalDate parseDate(String dateStr, String pattern) {
+		DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
+		return DateTimeUtil.parseDate(dateStr, formatter);
+	}
+
+	/**
+	 * 灏嗗瓧绗︿覆杞崲涓烘椂闂�
+	 *
+	 * @param dateStr   鏃堕棿瀛楃涓�
+	 * @param formatter DateTimeFormatter
+	 * @return 鏃堕棿
+	 */
+	public static LocalDate parseDate(String dateStr, DateTimeFormatter formatter) {
+		return LocalDate.parse(dateStr, formatter);
+	}
+
+	/**
+	 * 灏嗗瓧绗︿覆杞崲涓烘棩鏈�
+	 *
+	 * @param dateStr 鏃堕棿瀛楃涓�
+	 * @return 鏃堕棿
+	 */
+	public static LocalDate parseDate(String dateStr) {
+		return DateTimeUtil.parseDate(dateStr, DateTimeUtil.DATE_FORMAT);
+	}
+
+	/**
+	 * 灏嗗瓧绗︿覆杞崲涓烘椂闂�
+	 *
+	 * @param dateStr 鏃堕棿瀛楃涓�
+	 * @param pattern 鏃堕棿姝e垯
+	 * @return 鏃堕棿
+	 */
+	public static LocalTime parseTime(String dateStr, String pattern) {
+		DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
+		return DateTimeUtil.parseTime(dateStr, formatter);
+	}
+
+	/**
+	 * 灏嗗瓧绗︿覆杞崲涓烘椂闂�
+	 *
+	 * @param dateStr   鏃堕棿瀛楃涓�
+	 * @param formatter DateTimeFormatter
+	 * @return 鏃堕棿
+	 */
+	public static LocalTime parseTime(String dateStr, DateTimeFormatter formatter) {
+		return LocalTime.parse(dateStr, formatter);
+	}
+
+	/**
+	 * 灏嗗瓧绗︿覆杞崲涓烘椂闂�
+	 *
+	 * @param dateStr 鏃堕棿瀛楃涓�
+	 * @return 鏃堕棿
+	 */
+	public static LocalTime parseTime(String dateStr) {
+		return DateTimeUtil.parseTime(dateStr, DateTimeUtil.TIME_FORMAT);
+	}
+
+	/**
+	 * 鏃堕棿杞� Instant
+	 *
+	 * @param dateTime 鏃堕棿
+	 * @return Instant
+	 */
+	public static Instant toInstant(LocalDateTime dateTime) {
+		return dateTime.atZone(ZoneId.systemDefault()).toInstant();
+	}
+
+	/**
+	 * Instant 杞� 鏃堕棿
+	 *
+	 * @param instant Instant
+	 * @return Instant
+	 */
+	public static LocalDateTime toDateTime(Instant instant) {
+		return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
+	}
+
+	/**
+	 * 杞崲鎴� date
+	 *
+	 * @param dateTime LocalDateTime
+	 * @return Date
+	 */
+	public static Date toDate(LocalDateTime dateTime) {
+		return Date.from(DateTimeUtil.toInstant(dateTime));
+	}
+
+	/**
+	 * 姣旇緝2涓椂闂村樊锛岃法搴︽瘮杈冨皬
+	 *
+	 * @param startInclusive 寮�濮嬫椂闂�
+	 * @param endExclusive   缁撴潫鏃堕棿
+	 * @return 鏃堕棿闂撮殧
+	 */
+	public static Duration between(Temporal startInclusive, Temporal endExclusive) {
+		return Duration.between(startInclusive, endExclusive);
+	}
+
+	/**
+	 * 姣旇緝2涓椂闂村樊锛岃法搴︽瘮杈冨ぇ锛屽勾鏈堟棩涓哄崟浣�
+	 *
+	 * @param startDate 寮�濮嬫椂闂�
+	 * @param endDate   缁撴潫鏃堕棿
+	 * @return 鏃堕棿闂撮殧
+	 */
+	public static Period between(LocalDate startDate, LocalDate endDate) {
+		return Period.between(startDate, endDate);
+	}
+}

--
Gitblit v1.9.3