$timer = [System.Diagnostics.Stopwatch]::StartNew()
Start-Sleep -Second 83
$timer.stop
$elapsed=$timer.elapsed
Write-Host $elapsed < Works, but not shown in desired format
Write-Host $elapsed.ToString("DD:HH:MM:SS") < Overload error on .ToString and Argument count:"1"
Write-Host $($elapsed).ToString("DD:HH:MM:SS") < Overload error on .ToString and Argument count:"1"
I cannot get the elapsed time to output in the desired format (“DD:HH:MM:SS”; 2 digit days, hours, minutes and seconds). I’ve found quite a bit about formatting dates/times directly from Get-Date, and some even claim to show or calculate differences between a start and end time. But I keep getting Overload errors on any attempt to enforce formatting.
New contributor
NewbieBAT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.