mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 19:00:24 +00:00
优化DateTimeUtil时间戳转DateTime接口时区的问题
This commit is contained in:
@@ -6,8 +6,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
public static class DateTimeUtil
|
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 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
||||||
private static readonly DateTime k_DateTime1970 = new DateTime(1970, 1, 1);
|
|
||||||
public static readonly int ONE_SECOND = 1;
|
public static readonly int ONE_SECOND = 1;
|
||||||
public static readonly int ONE_MINUTE = ONE_SECOND * 60;
|
public static readonly int ONE_MINUTE = ONE_SECOND * 60;
|
||||||
public static readonly int ONE_HOUR = ONE_MINUTE * 60;
|
public static readonly int ONE_HOUR = ONE_MINUTE * 60;
|
||||||
@@ -34,10 +33,21 @@ namespace XCharts.Runtime
|
|||||||
return (int)(time - k_DateTime1970).TotalSeconds;
|
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)
|
public static DateTime GetDateTime(int timestamp)
|
||||||
{
|
{
|
||||||
long span = ((long)timestamp) * 10000000;
|
return k_DateTime1970.AddSeconds(timestamp);
|
||||||
return k_DateTime1970.Add(new TimeSpan(span));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string GetDateTimeFormatString(DateTime dateTime, double range)
|
internal static string GetDateTimeFormatString(DateTime dateTime, double range)
|
||||||
|
|||||||
Reference in New Issue
Block a user