using cfg.ActorCfg;
using cfg.CharacterCfg;
using Framework;
using Gameplay.Net;
using System;
namespace Gameplay
{
public partial class CommonUtils
{
public enum E_TimeType
{
///
/// 本地
///
Local,
///
/// 服务器
///
Server,
}
private static readonly DateTime Epoch = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
///
/// 根据时间戳获取时间
///
/// 秒
///
public static DateTime GetTimeByTimestamp(uint timestamp)
{
return Epoch.AddSeconds(timestamp).ToLocalTime();
}
///
/// 根据时间戳获取时间
///
/// 毫秒
///
public static DateTime GetTimeByTimestamp(ulong timestamp)
{
return Epoch.AddMilliseconds(timestamp).ToLocalTime();
}
///
/// 获取当前时间
///
///
///
public static DateTime GetCurTime(E_TimeType timeType)
{
return timeType switch
{
E_TimeType.Local => DateTime.Now,
E_TimeType.Server => GetTimeByTimestamp(NetManager.Instance.ServerTimeMS),
_ => DateTime.MinValue,
};
}
///
/// 判断时间是否是上午
///
///
/// true:上午,false:下午
public static bool IsAM(DateTime dateTime)
{
return dateTime.Hour < 12;
}
///
/// 判断是否是生日
///
///
///
public static bool IsBirth(DateTime birthTime)
{
DateTime curTime = GetCurTime(E_TimeType.Server);
return curTime.Month == birthTime.Month && curTime.Day == birthTime.Day;
}
}
}