Display millisecs in hours, minutes and seconds

ddanbe 0 Tallied Votes 1K Views Share

Sometimes you have long processes and you even want display them up to the millisecond. Here is a way to do it.

private static string ConvertToHMSmsString(long ms)
{
    TimeSpan t = TimeSpan.FromMilliseconds(ms);
    string answer = $"{t.Hours:D2}h:{t.Minutes:D2}m:{t.Seconds:D2}s:{t.Milliseconds:D3}ms";
    return answer;
}