C # How to convert Environment.TickCount to HH: mm: ss: ms

I am trying to convert the value of int Environment.TickCount to the format dd: HH: mm: ss: ms (days: hours: minutes: seconds: milliseconds)

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

+7
c # int valueconverter
source share
1 answer

I would use the TimeSpan structure and, in particular, the FromMilliseconds static method :

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

then you have all the values ​​you need and you can use the various ToString options, namely something like

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

Check out this article on MSDN for custom TimeSpan formats.

+9
source share

All Articles