1. 程式人生 > >C# 日期操作

C# 日期操作

DataTime_API詳解

dataTime 詳解

例子:操作用時顯示方法

private void GetTime(float timer)
    {
        int s = ((int)timer) % 60;
        int m = ((int)timer) / 60;
        int h;
        if (m > 0)
        {
            h = m / 60;
        }
        else
        {
            h = 0;
        }

        if (h > 0)
        {
            m = m - h * 60;
        }
        e_time.text = DateTime.Parse(h + ":" + m + ":" + s).ToString("HH:mm:ss");
    }

    private void GetTime_1(float s)
    {
        DateTime iterm = new DateTime();
        iterm = iterm.AddSeconds(s);
        e_time.text = string.Format("{0:HH:mm:ss}", iterm);
    }
    private void GetTime_1(DateTime beforeTime)
    {
        DateTime iterm = new DateTime();
        TimeSpan timeSpan = DateTime.Now - beforeTime;
        iterm += timeSpan;
        e_time.text = iterm.ToString("HH:mm:ss");
    }