C# How to convert Environment.TickCount into HH:mm:ss:ms
Asked Answered
S

1

7

I'm trying to convert an int value Environment.TickCount into a format dd:HH:mm:ss:ms (days:hours:minutes:seconds:milliseconds)

Is there an easy way to do it or should I divide Environment.TickCount by 60 then by 3600 then by 216000, etc ?

Stogy answered 29/7, 2013 at 12:37 Comment(0)
S
11

I'd use a TimeSpan structure and in particular the FromMilliseconds static method:

var timespan = TimeSpan.FromMilliseconds(Environment.TickCount);

then you have all the values you want and you can use the various ToString options as well, namely something like

timespan.ToString("dd:hh:mm:ss:ff")

Check out this article on MSDN for the custom TimeSpan string formats.

Serigraph answered 29/7, 2013 at 12:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.