Convert time 121.419419 in minutes / seconds

I would like to calculate the execution time of my script, but my result from the receipt date is in the total second.

How can I convert this value to 31:14:12: hours: minutes: seconds?

+6
source share
2 answers
PS> $ts = New-TimeSpan -Seconds 1234567 PS> '{0:00}:{1:00}:{2:00}' -f $ts.Hours,$ts.Minutes,$ts.Seconds 06:56:07 

or

 PS> "$ts" -replace '^\d+?\.' 06:56:07 
+13
source

All you have to do is use the Measure-Command cmdlet to get the time:

 PS > measure-command { sleep 5} Days : 0 Hours : 0 Minutes : 0 Seconds : 5 Milliseconds : 13 Ticks : 50137481 TotalDays : 5.80294918981481E-05 TotalHours : 0.00139270780555556 TotalMinutes : 0.0835624683333333 TotalSeconds : 5.0137481 TotalMilliseconds : 5013.7481 

The above output may be good enough for you, or you can format it accordingly, since the Measure-Command output is a TimeSpan object. Or you can use ToString :

 PS > (measure-command { sleep 125}).tostring() 00:02:05.0017446 
+7
source

Source: https://habr.com/ru/post/905224/


All Articles