Browse Source

新增时间工具类,转化utc为上海

tags/v20240126
fans 2 years ago
parent
commit
b4b292cea2
2 changed files with 36 additions and 3 deletions
  1. +3
    -3
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java
  2. +33
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DateUtils.java

+ 3
- 3
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java View File

@@ -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);
}



+ 33
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DateUtils.java View File

@@ -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;
}

}

Loading…
Cancel
Save