From 54870ccdfa9aa92613097a068036517053728d3b Mon Sep 17 00:00:00 2001 From: Jian Tao Date: Thu, 14 Mar 2019 19:36:32 -0400 Subject: [PATCH] Fix bug of TimeUtils.GetCurrentTime, when the current machine is in daylight saving time. --- QCloudCSharpSDK/COSXML/Utils/TimeUtils.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/QCloudCSharpSDK/COSXML/Utils/TimeUtils.cs b/QCloudCSharpSDK/COSXML/Utils/TimeUtils.cs index 984cb52..074ba81 100644 --- a/QCloudCSharpSDK/COSXML/Utils/TimeUtils.cs +++ b/QCloudCSharpSDK/COSXML/Utils/TimeUtils.cs @@ -11,10 +11,11 @@ namespace COSXML.Utils { public sealed class TimeUtils { + private static readonly long epochTicks = (new DateTime(1970, 1, 1)).Ticks; public static long GetCurrentTime(TimeUnit timeUnit) { - TimeSpan timeSpan = TimeZone.CurrentTimeZone.ToLocalTime(DateTime.UtcNow) - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); + var timeSpan = TimeSpan.FromTicks(DateTime.UtcNow.Ticks - epochTicks); long result = -1L; switch (timeUnit) {