diff --git a/pom.xml b/pom.xml index 14cd64a..24bb16a 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 664197b..9cbb459 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 ca2b196..fc6ff64 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;