From 00bb8d914a5a48bae84f20bf1891b7462605a0dc Mon Sep 17 00:00:00 2001 From: leesam Date: Fri, 15 Mar 2024 09:42:25 +0800 Subject: [PATCH] =?UTF-8?q?[bugfix]=E4=BF=AE=E5=A4=8D=E4=BA=91=E7=AB=AF?= =?UTF-8?q?=E5=BD=95=E5=83=8F=E6=9F=A5=E8=AF=A2=E6=97=B6=E9=97=B4=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CloudRecordServiceImpl.java | 4 ++-- .../com/genersoft/iot/vmp/utils/DateUtil.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/CloudRecordServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/CloudRecordServiceImpl.java index f160aacc..a23252f6 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/CloudRecordServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/CloudRecordServiceImpl.java @@ -59,14 +59,14 @@ public class CloudRecordServiceImpl implements ICloudRecordService { if (!DateUtil.verification(startTime, DateUtil.formatter)) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "开始时间格式错误,正确格式为: " + DateUtil.formatter); } - startTimeStamp = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime); + startTimeStamp = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestampMs(startTime); } if (endTime != null ) { if (!DateUtil.verification(endTime, DateUtil.formatter)) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "结束时间格式错误,正确格式为: " + DateUtil.formatter); } - endTimeStamp = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime); + endTimeStamp = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestampMs(endTime); } PageHelper.startPage(page, count); diff --git a/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java index 2bb9bfb1..ddcbb213 100755 --- a/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java @@ -106,6 +106,26 @@ public class DateUtil { return formatter.format(LocalDateTime.ofInstant(instant, ZoneId.of(zoneStr))); } + /** + * yyyy_MM_dd_HH_mm_ss 转时间戳(毫秒) + * + * @param formatTime + * @return + */ + public static long yyyy_MM_dd_HH_mm_ssToTimestampMs(String formatTime) { + TemporalAccessor temporalAccessor = formatter.parse(formatTime); + Instant instant = Instant.from(temporalAccessor); + return instant.toEpochMilli(); + } + + /** + * 时间戳(毫秒) 转 yyyy_MM_dd_HH_mm_ss + */ + public static String timestampMsTo_yyyy_MM_dd_HH_mm_ss(long timestamp) { + Instant instant = Instant.ofEpochMilli(timestamp); + return formatter.format(LocalDateTime.ofInstant(instant, ZoneId.of(zoneStr))); + } + /** * 时间戳 转 yyyy_MM_dd */