diff --git a/internal/handler/sensor.go b/internal/handler/sensor.go index 0cd20d6..dacab1b 100644 --- a/internal/handler/sensor.go +++ b/internal/handler/sensor.go @@ -146,6 +146,14 @@ func (h *SensorHandler) GetLatestSensorRawData(w http.ResponseWriter, r *http.Re return } + // 将时间调整为中国时区(UTC+8) + chinaLoc, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + // 如果无法加载时区,手动创建UTC+8的时区 + chinaLoc = time.FixedZone("CST", 8*60*60) + } + chinaTime := data.Timestamp.In(chinaLoc) + // 转换为前端友好的格式 response := struct { ID int64 `json:"id"` @@ -163,7 +171,7 @@ func (h *SensorHandler) GetLatestSensorRawData(w http.ResponseWriter, r *http.Re }{ ID: data.ID, Timestamp: data.Timestamp, - FormattedTime: data.Timestamp.Format("2006-01-02 15:04:05"), + FormattedTime: chinaTime.Format("2006-01-02 15:04:05"), WindSpeed: float64(data.WindSpeed) / 100.0, WindForce: data.WindForce, WindDirection8: data.WindDirection8, diff --git a/static/index.html b/static/index.html index d86668c..3ca48a4 100644 --- a/static/index.html +++ b/static/index.html @@ -75,8 +75,9 @@ } .data-value { - font-size: 18px; - color: #007bff; + font-size: 20px; + /*color: #007bff;*/ + color: #555; } .data-unit {