From a30622b46051a3c22cf47a15a2280adfcce66290 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 26 Feb 2022 09:59:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7spring-boot=E5=88=B0=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC2.6.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../ruoyi/common/core/utils/DateUtils.java | 6 +++- .../common/core/utils/poi/ExcelUtil.java | 30 ++++++++++++------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 14cd64ae..24bb16a1 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ UTF-8 UTF-8 1.8 - 2.6.3 + 2.6.4 2021.0.1 2021.1 2.0.4 diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateUtils.java index 664197b9..9cbb459b 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateUtils.java @@ -3,7 +3,11 @@ package com.ruoyi.common.core.utils; import java.lang.management.ManagementFactory; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.time.*; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Date; import org.apache.commons.lang3.time.DateFormatUtils; diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java index ca2b1965..fc6ff641 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java @@ -284,7 +284,7 @@ public class ExcelUtil String dateFormat = field.getAnnotation(Excel.class).dateFormat(); if (StringUtils.isNotEmpty(dateFormat)) { - val = this.parseDateToStr(dateFormat, (Date) val); + val = parseDateToStr(dateFormat, (Date) val); } else { @@ -703,7 +703,7 @@ public class ExcelUtil String separator = attr.separator(); if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) { - cell.setCellValue(this.parseDateToStr(dateFormat, (Date) value)); + cell.setCellValue(parseDateToStr(dateFormat, (Date) value)); } else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) { @@ -1158,25 +1158,33 @@ public class ExcelUtil } /** - * 增加ExcelUtil对java8 日期的支持 - * 格式化日期,日期可能是:{@link Date}、{@link LocalDateTime}、 {@link LocalDate} 其他日期暂不支持 + * 格式化不同类型的日期对象 + * * @param dateFormat 日期格式 * @param val 被格式化的日期对象 - * @see DateUtils#parseDateToStr(String, Date) + * @return 格式化后的日期字符 */ - private String parseDateToStr(final String dateFormat, Object val) + public String parseDateToStr(String dateFormat, Object val) { - if (val == null) { + if (val == null) + { return ""; } String str; - if (val instanceof Date) { + if (val instanceof Date) + { str = DateUtils.parseDateToStr(dateFormat, (Date) val); - } else if (val instanceof LocalDateTime) { + } + else if (val instanceof LocalDateTime) + { str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDateTime) val)); - } else if (val instanceof LocalDate) { + } + else if (val instanceof LocalDate) + { str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDate) val)); - } else { + } + else + { str = val.toString(); } return str;