对于 .Net <= 4.0,请使用TimeSpan类。
TimeSpan t = TimeSpan.FromSeconds( secs );string answer = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms", t.Hours, t.Minutes, t.Seconds, t.Milliseconds);(如Inder Kumar Rathore所述)对于 .NET > 4.0,您可以使用
TimeSpan time = TimeSpan.FromSeconds(seconds);//here backslash is must to tell that colon is//not the part of format, it just a character that we want in outputstring str = time .ToString(@"hh:mm:ss:fff");
(摘自Nick Molyneux)确保秒数小于
TimeSpan.MaxValue.TotalSeconds避免发生异常的时间。



