From e2120b3da667d6f966a017a72df92d63ccf42b96 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 16 Apr 2024 22:30:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96`DateTimeUtil`=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=88=B3=E8=BD=AC`DateTime`=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=97=B6=E5=8C=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Utilities/DateTimeUtil.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Runtime/Utilities/DateTimeUtil.cs b/Runtime/Utilities/DateTimeUtil.cs index 7c14cfe5..c47ae94d 100644 --- a/Runtime/Utilities/DateTimeUtil.cs +++ b/Runtime/Utilities/DateTimeUtil.cs @@ -6,8 +6,7 @@ namespace XCharts.Runtime { public static class DateTimeUtil { - //private static readonly DateTime k_DateTime1970 = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local); - private static readonly DateTime k_DateTime1970 = new DateTime(1970, 1, 1); + private static readonly DateTime k_DateTime1970 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); public static readonly int ONE_SECOND = 1; public static readonly int ONE_MINUTE = ONE_SECOND * 60; public static readonly int ONE_HOUR = ONE_MINUTE * 60; @@ -34,10 +33,21 @@ namespace XCharts.Runtime return (int)(time - k_DateTime1970).TotalSeconds; } + public static int GetTimestamp(string dateTime) + { + try + { + return GetTimestamp(DateTime.Parse(dateTime)); + } + catch (Exception e) + { + throw e; + } + } + public static DateTime GetDateTime(int timestamp) { - long span = ((long)timestamp) * 10000000; - return k_DateTime1970.Add(new TimeSpan(span)); + return k_DateTime1970.AddSeconds(timestamp); } internal static string GetDateTimeFormatString(DateTime dateTime, double range)