少年修仙传客户端代码仓库
hch
2025-03-19 6770e1eb64c4282def45adb824b14b2a407fdd30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using LitJson;
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
 
 
public static class ILTimeUtility
{
    //角色在子服收到的跨服时间,和TimeUtility.CrossServerNow接收时机不一样(角色在跨服服务器的时间)
    private static DateTime s_ServerCrossTime = DateTime.Now;
 
    private static float _checkTime = 0;
    /// <summary>
    /// 当前跨服服务器时间(子服收到的跨服时间)
    /// </summary>
    public static DateTime ServerCrossNow
    {
        get
        {
            float tick = Time.realtimeSinceStartup - _checkTime;
            DateTime real = s_ServerCrossTime.AddSeconds(tick);
            return real;
        }
        private set
        {
            s_ServerCrossTime = value;
            OnServerTimeRefresh?.Invoke();
        }
    }
    public static event Action OnServerTimeRefresh;
    public static void OnRefreshServerTime(HA004_tagServerDateTime vNetData)
    {
        _checkTime = Time.realtimeSinceStartup;
        ServerCrossNow = Convert.ToDateTime(vNetData.CrossServerTime);
    }
 
    //跨服时间戳
    public static int CSAllSeconds
    {
        get
        {
            TimeSpan t = TimeUtility.CrossServerNow - TimeUtility.OriginalTime;
            return (int)t.TotalSeconds;
        }
    }
 
 
    //例子
    //大于1天的显示:x天
    //xx:xx:xx
    public static string SecondsToDHMSEx(int _seconds)
    {
        int days = _seconds / 86400;
        int hours = _seconds % 86400 / 3600;
        int mins = _seconds % 3600 / 60;
        int seconds = _seconds % 60;
        if (days > 0)
        {
            return StringUtility.Contact(days, Language.Get("L1074"));
        }
        return StringUtility.Contact(hours.ToString("D2"), ":", mins.ToString("D2"), ":", seconds.ToString("D2"));
    }
}