diff --git a/backend/src/main/java/io/metersphere/report/JtlResolver.java b/backend/src/main/java/io/metersphere/report/JtlResolver.java index a26b8535e4..2801927e00 100644 --- a/backend/src/main/java/io/metersphere/report/JtlResolver.java +++ b/backend/src/main/java/io/metersphere/report/JtlResolver.java @@ -13,6 +13,11 @@ import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -414,16 +419,16 @@ public class JtlResolver { String startTimeStamp = totalLineList.get(0).getTimestamp(); String endTimeStamp = totalLineList.get(totalLineList.size()-1).getTimestamp(); - String startTime = stampToDate(startTimeStamp); - String endTime = stampToDate(endTimeStamp); + + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); + String startTime = dtf.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(startTimeStamp)), ZoneId.systemDefault())); + String endTime = dtf.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(endTimeStamp)), ZoneId.systemDefault())); reportTimeInfo.setStartTime(startTime); reportTimeInfo.setEndTime(endTime); - Date startDate = new Date(Long.parseLong(startTimeStamp)); - Date endDate = new Date(Long.parseLong(endTimeStamp)); - long timestamp = endDate.getTime() - startDate.getTime(); - reportTimeInfo.setDuration(String.valueOf(timestamp*1.0 / 1000 / 60)); - + // todo 时间问题 + long seconds = Duration.between(Instant.ofEpochMilli(Long.parseLong(startTimeStamp)), Instant.ofEpochMilli(Long.parseLong(endTimeStamp))).getSeconds(); + reportTimeInfo.setDuration(String.valueOf(seconds)); return reportTimeInfo; } diff --git a/frontend/src/business/components/performance/report/PerformanceReportView.vue b/frontend/src/business/components/performance/report/PerformanceReportView.vue index aed096cb2d..3122b407c8 100644 --- a/frontend/src/business/components/performance/report/PerformanceReportView.vue +++ b/frontend/src/business/components/performance/report/PerformanceReportView.vue @@ -20,7 +20,7 @@ - 持续时间: {{duration}} 分钟 + 持续时间: {{minutes}} 分钟 {{seconds}} 秒 开始时间: {{startTime}} @@ -78,7 +78,8 @@ projectName: '', startTime: '0', endTime: '0', - duration: '0' + minutes: '0', + seconds: '0' } }, methods: { @@ -101,7 +102,9 @@ if(data){ this.startTime = data.startTime; this.endTime = data.endTime; - this.duration = data.duration; + let duration = data.duration; + this.minutes = Math.floor(duration / 60); + this.seconds = duration % 60; } }) }