yyl
2026-02-11 45d3d873a7740886fa09f35c9fea2830f4563072
Main/Utility/TimeUtility.cs
@@ -100,6 +100,15 @@
        }
    }
    public static int AllSecondsCrossServer
    {
        get
        {
            TimeSpan t = CrossServerNow - OriginalTime;
            return (int)t.TotalSeconds;
        }
    }
    //1年中的第几周,以服务端为准,python和c#算出来不一样
    public static int WeekOfYear
    {
@@ -184,8 +193,11 @@
            OnServerTimeRefresh();
        }
        s_CrossServerTime = Convert.ToDateTime(vNetData.CrossServerTime);
        _crossCheckTime = Time.realtimeSinceStartup;
        if (!string.IsNullOrEmpty(vNetData.CrossServerTime))
        {
            s_CrossServerTime = Convert.ToDateTime(vNetData.CrossServerTime);
            _crossCheckTime = Time.realtimeSinceStartup;
        }
        TimeDownMgr.Instance.Begin(TimeDownMgr.CoolTimeType.SyncServerTime, 60, (float tick) =>
        {
@@ -538,4 +550,40 @@
    {
        return (int)(GetTodayEndTime() - ServerNow).TotalSeconds;
    }
    #region 跨服和本服公用接口
    //当有的功能会从本服功能变成跨服功能的时候统一用这些接口处理时间
    //各自的功能传自己的zoneID
    // 获取当前时间, 公会跨区前取本服时间,跨服后取跨服时间
    public static DateTime GetCommServerNow(int zoneID = 0)
    {
        if (zoneID == 0)
        {
            return ServerNow;
        }
        else
        {
            return CrossServerNow;
        }
    }
    public static int GetCommServerTick(int zoneID = 0)
    {
        if (zoneID == 0)
        {
            return AllSeconds;
        }
        else
        {
            return AllSecondsCrossServer;
        }
    }
    public static DateTime GetCommTodayEndTime(int zoneID = 0)
    {
        var now = GetCommServerNow(zoneID).AddDays(1);
        return new DateTime(now.Year, now.Month, now.Day);
    }
    #endregion
}