Pages

Monday, 20 June 2011

Best way to convert seconds into (Hour:Minutes:Seconds:Milliseconds) time?

Just use 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);

No comments:

Post a Comment