Convert Seconds into (Hour:Minutes:Seconds:Milliseconds) Time
To convert seconds into a formatted time string, consider the following solutions:
For .NET <= 4.0:
Utilize the TimeSpan class:
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);
For .NET > 4.0:
Use the TimeSpan class with a custom format string:
TimeSpan time = TimeSpan.FromSeconds(seconds); // backslash is essential to indicate that colon is not part of the format string str = time.ToString(@"hh\:mm\:ss\:fff");
Important Notes:
The above is the detailed content of How to Convert Seconds to HH:MM:SS:FFF Time Format in .NET?. For more information, please follow other related articles on the PHP Chinese website!