kingBook

导航

unity 获取网络时间

http://cgi.im.qq.com/cgi-bin/cgi_svrtime

 public int year, mouth, day, hour, min, sec;

    public string timeURL = "http://cgi.im.qq.com/cgi-bin/cgi_svrtime";

    void Start () 
    {
        StartCoroutine(GetTime());
    }

    IEnumerator GetTime()
    {
        WWW www = new WWW(timeURL);
        while (!www.isDone)
        {
            yield return www;
        }
        SplitTime(www.text);
    }

    void SplitTime(string dateTime)
    {
        dateTime = dateTime.Replace("-", "|");
        dateTime = dateTime.Replace(" ", "|");
        dateTime = dateTime.Replace(":", "|");
        string[] Times = dateTime.Split('|');
        year = int.Parse(Times[0]);
        mouth = int.Parse(Times[1]);
        day = int.Parse(Times[2]);
        hour = int.Parse(Times[3]);
        min = int.Parse(Times[4]);
        sec = int.Parse(Times[5]);
    }

posted on 2018-08-14 17:38  kingBook  阅读(495)  评论(0编辑  收藏  举报