Files
TEngine/Assets/GameScripts/DotNet/Core/Helper/TimeHelper.cs
ALEXTANG 0c8f3a5f92 [+] TEngineServer
[+] TEngineServer
2023-07-13 17:17:26 +08:00

36 lines
1.1 KiB
C#

using System;
namespace TEngine.Core
{
public static class TimeHelper
{
public const long Hour = 3600000; // 小时毫秒值 60 * 60 * 1000
public const long Minute = 60000; // 分钟毫秒值 60 * 1000
public const long OneDay = 86400000; // 天毫秒值 24 * 60 * 60 * 1000
private const long Epoch = 621355968000000000L; // 1970年1月1日的Ticks
private static readonly DateTime Dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static long Now => (DateTime.UtcNow.Ticks - Epoch) / 10000;
#if TENGINE_UNITY
public static long TimeDiff;
public static long ServerNow => Now + TimeDiff;
#endif
public static long Transition(DateTime d)
{
return (d.Ticks - Epoch) / 10000;
}
public static DateTime Transition(long timeStamp)
{
return Dt1970.AddTicks(timeStamp);
}
public static DateTime TransitionLocal(long timeStamp)
{
return Dt1970.AddTicks(timeStamp).ToLocalTime();
}
}
}