I would like to format some commands execution times in a human readable format, for example:
3 -> 3ms
1100 -> 1s 100ms
62000 -> 1m 2s
etc ..
Taking into account days, hours, minutes, seconds, ...
Is it possible using C#
?
I would like to format some commands execution times in a human readable format, for example:
3 -> 3ms
1100 -> 1s 100ms
62000 -> 1m 2s
etc ..
Taking into account days, hours, minutes, seconds, ...
Is it possible using C#
?
This probably has a slightly different output than requested, but the result is human readable - and it can be adapted to fit many other use cases.
Example calls...
...and results:
Maybe something like this?
I know this is old, but I wanted to answer with a great nuget package.
https://www.nuget.org/packages/Humanizer
https://github.com/MehdiK/Humanizer
Example from their readme.md
You could utilize the static
TimeSpan.FromMilliseconds
method as well as the resultingTimeSpan
'sDays
,Hours
,Minutes
,Seconds
andMilliseconds
properties.But I'm busy right now, so I'll leave the rest to you as an exercise.
.NET 4 accepts format in
TimeSpan.Tostring()
.For other you can implement extension method like
and call as