Unity时间格式、显示成秒表、毫秒格式 C#

一、时分秒格式

 public string TimeToString(int result)
    {
        int hour = (int)result / 3600;
        int minute = ((int)result - hour * 3600) / 60;
        int second = (int)result - hour * 3600 - minute * 60;
        string data = string.Format("{0:D2}:{1:D2}:{2:D2}", hour, minute, second);
        return data;
    }

输入值,显示时间格式为HH:MM:SS

二、时分秒.毫秒格式

public string TimeToString(int result)
    {
        int hour = (int)result / 3600;
        int minute = ((int)result - hour * 3600) / 60;
        int second = (int)result - hour * 3600 - minute * 60;
        int millisecond = (int)((result - (int)result ) * 1000);
        string data = string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", hour, minute, second, millisecond);
        return data;
    }

输入值,显示时间格式为HH:MM:SS.ms

欢迎留言转载~~谢谢

你可能感兴趣的:(Unity3D)