diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java index fa1eebf8..357701a5 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java @@ -6,6 +6,7 @@ import com.ruoyi.platform.mapper.ExperimentDao; import com.ruoyi.platform.mapper.ExperimentInsDao; import com.ruoyi.platform.service.ExperimentInsService; import com.ruoyi.platform.service.WorkflowService; +import com.ruoyi.platform.utils.DateUtils; import com.ruoyi.platform.utils.HttpUtils; import com.ruoyi.platform.utils.JsonUtils; import com.ruoyi.system.api.model.LoginUser; @@ -245,14 +246,13 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { //解析流水线开始时间,开始时间一定存在,所以不需要判断 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - String startedAtString = (String) status.get("startedAt"); - Date startTime = dateFormat.parse(startedAtString); + Date startTime = DateUtils.convertUTCtoShanghaiDate((String) status.get("startedAt")); experimentIns.setStartTime(startTime); //解析流水线结束时间 String finishedAtString = (String) status.get("finishedAt"); if (finishedAtString != null && !finishedAtString.isEmpty()) { - Date finishTime = dateFormat.parse(finishedAtString); + Date finishTime = DateUtils.convertUTCtoShanghaiDate(finishedAtString); experimentIns.setFinishTime(finishTime); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DateUtils.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DateUtils.java new file mode 100644 index 00000000..a426ba57 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DateUtils.java @@ -0,0 +1,33 @@ +package com.ruoyi.platform.utils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + +public class DateUtils { + + public static Date convertUTCtoShanghaiDate(String utcTime) throws ParseException { + + // Create a SimpleDateFormat object with the UTC date format + SimpleDateFormat utcFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + utcFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); + + // Parse the UTC time string into a Date object + Date utcDate = utcFormatter.parse(utcTime); + + // Create a SimpleDateFormat object with the Shanghai date format + SimpleDateFormat shanghaiFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + shanghaiFormatter.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); + + // Format the UTC Date object in Shanghai time + String shanghaiTime = shanghaiFormatter.format(utcDate); + + // Parse the Shanghai time string into a Date object + Date shanghaiDate = shanghaiFormatter.parse(shanghaiTime); + + // Return the Shanghai Date object + return shanghaiDate; + } + +}