2024-03-25 15:53:35 +08:00
|
|
|
|
using cfg.ActorCfg;
|
|
|
|
|
|
using cfg.CharacterCfg;
|
|
|
|
|
|
using Framework;
|
|
|
|
|
|
using Gameplay.Net;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Gameplay
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class CommonUtils
|
|
|
|
|
|
{
|
|
|
|
|
|
public enum E_TimeType
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 本地
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
Local,
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 服务器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
Server,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly DateTime Epoch = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
|
|
|
2024-03-26 16:27:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据时间戳获取时间
|
|
|
|
|
|
/// </summary>
|
2024-04-03 16:07:49 +08:00
|
|
|
|
/// <param name="timestamp">秒</param>
|
2024-03-26 16:27:09 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static DateTime GetTimeByTimestamp(uint timestamp)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Epoch.AddSeconds(timestamp).ToLocalTime();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据时间戳获取时间
|
|
|
|
|
|
/// </summary>
|
2024-04-03 16:07:49 +08:00
|
|
|
|
/// <param name="timestamp">毫秒</param>
|
2024-03-26 16:27:09 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static DateTime GetTimeByTimestamp(ulong timestamp)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Epoch.AddMilliseconds(timestamp).ToLocalTime();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-25 15:53:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取当前时间
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="timeType"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static DateTime GetCurTime(E_TimeType timeType)
|
|
|
|
|
|
{
|
|
|
|
|
|
return timeType switch
|
|
|
|
|
|
{
|
|
|
|
|
|
E_TimeType.Local => DateTime.Now,
|
2024-03-26 16:27:09 +08:00
|
|
|
|
E_TimeType.Server => GetTimeByTimestamp(NetManager.Instance.ServerTimeMS),
|
2024-03-25 15:53:35 +08:00
|
|
|
|
_ => DateTime.MinValue,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 判断时间是否是上午
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dateTime"></param>
|
|
|
|
|
|
/// <returns>true:上午,false:下午</returns>
|
|
|
|
|
|
public static bool IsAM(DateTime dateTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
return dateTime.Hour < 12;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|