Skip to content

Commit 1afb7c3

Browse files
committed
fix(Time): 修正 GetNow 方法以使用 CurrentTimeZone 进行时区转换
之前 GetNow 直接使用 DateTime.Now,这依赖于系统本地时区设置,可能导致跨时区环境下的时间不一致。现在改为从 UTC 时间根据 CurrentTimeZone 显式转换,确保时间计算基于统一配置的时区。
1 parent 70dd446 commit 1afb7c3

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

GameFrameX.Foundation.Utility/Time/TimerHelper.Current.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ public static DateTime GetUtcNow()
151151
/// <returns>当前时间</returns>
152152
/// <remarks>
153153
/// 此方法返回当前的本地时间
154-
/// 会根据系统设置的时区自动调整
154+
/// 会根据设置的时区(<see cref="CurrentTimeZone"/>)自动调整
155155
/// 主要用于需要显示本地时间的场景
156156
/// </remarks>
157157
public static DateTime GetNow()
158158
{
159-
return DateTime.Now;
159+
return TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, CurrentTimeZone);
160160
}
161161
}

0 commit comments

Comments
 (0)