From 7052c78ee93e552ed061c830a6bddc06acabd147 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Fri, 11 Jul 2025 16:36:23 +0800
Subject: [PATCH] 时间

---
 src/main/java/project/web/api/RealtimeController.java |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/main/java/project/web/api/RealtimeController.java b/src/main/java/project/web/api/RealtimeController.java
index 042ab1d..b0bf725 100644
--- a/src/main/java/project/web/api/RealtimeController.java
+++ b/src/main/java/project/web/api/RealtimeController.java
@@ -3,6 +3,11 @@
 import java.math.RoundingMode;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -99,13 +104,23 @@
 			Map<String, Object> map = new HashMap<String, Object>();
 			map.put("symbol", realtime.getSymbol());
 			map.put("ts", realtime.getTs());
-			long currentTime = 1744341503535L; // 确保 currentTime 是 long 类型
-			TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
-			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-			sdf.setTimeZone(timeZone);
-			Date date = new Date(currentTime);
-			String formattedTime = sdf.format(date);
+			String currentTime = realtime.getCurrent_time(); // "yyyy-MM-dd HH:mm:ss"
+
+			// 1. 解析原始时间(假设是 UTC 时间)
+			DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+			LocalDateTime localDateTime = LocalDateTime.parse(currentTime, inputFormatter);
+
+			// 2. 转换为柏林时区的时间
+			ZoneId berlinZone = ZoneId.of("Europe/Berlin");
+			ZonedDateTime utcTime = localDateTime.atZone(ZoneOffset.UTC); // 假设原时间是 UTC
+			ZonedDateTime berlinTime = utcTime.withZoneSameInstant(berlinZone);
+
+			// 3. 格式化为字符串
+			DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+			String formattedTime = berlinTime.format(outputFormatter);
+
 			map.put("current_time", formattedTime);
+
 			Item item1 = this.itemService.cacheBySymbol(realtime.getSymbol(), false);
 			map.put("name", item1.getName());
 			map.put("change_ratio", realtime.getChange_ratio());

--
Gitblit v1.9.3