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

This commit is contained in:
fans 2024-01-18 14:05:50 +08:00
parent 1797d474a3
commit b4b292cea2
2 changed files with 36 additions and 3 deletions

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

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