1. 程式人生 > >C#實現毫秒到格式化時間串

C#實現毫秒到格式化時間串

using System;
public class Test{
      static void Main(string[] args){
             float timeMs = 100000;
             String str = FormatTimeMsToStr(float time);
             Console.WriteLine(str);Console.ReadLine();
       }
       public static string FormatTimeMsToStr(float time){
                int second ;
        int minute = 0;
        second = (int)time / 1000;
        if (second >= 60) {
            minute = second / 60;
            second = second % 60;
        }
//        Debug.Log(string.Format ("{0:D2}:{1:D2}", minute,second));
        return string.Format ("{0:D2}:{1:D2}", minute,second);
        }
}將時間格式化為00:00的格式