When I´m using the folling PowerShell code, I´m getting results like 123.0000232 for example.
Is is there a paramter to format the result?
I want a result like 123
$TimeStart = Get-Date
#some code
sleep 2
(New-TimeSpan -Start $TimeStart -End $(Get-Date)).TotalSeconds
Thank you in advance
The Get-Date cmdlet gets a DateTime object that represents the current date or a date that you specify. Get-Date can format the date and time in several . NET and UNIX formats. You can use Get-Date to generate a date or time character string, and then send the string to other cmdlets or programs.
You could do one of two things:
Use the seconds attribute, which is an int32
(New-TimeSpan -Start $TimeStart -End $(Get-Date)).Seconds
or Typecast TotalSeconds to [int32] (not so nice, but works too)
[int32] (New-TimeSpan -Start $TimeStart -End $(Get-Date)).TotalSeconds
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With