Time formatting oddness
in bit of code below, first formatted time showing want. however, second approach should, seems me, showing same. however, showing leading zeros, , milliseconds either truncated when should 000, or showing 7 digits not 3 specified, thus:
days : 0hours : 0
minutes : 0
seconds : 3
milliseconds : 1
ticks : 30010000
totaldays : 3.47337962962963e-05
totalhours : 0.000833611111111111
totalminutes : 0.0500166666666667
totalseconds : 3.001
totalmilliseconds : 3001
0:0:3.001
00:00:03.0010000
any thoughts on have gone wrong on seemingly simple?
and, there super simple approach getting culture specific decimal seperator?
and... merry christmas!
$stopwatch = new-object system.diagnostics.stopwatch$stopwatch.start()
start-sleep -s:3
$stopwatch.stop()
$time = [timespan]::frommilliseconds($stopwatch.elapsedmilliseconds)
$formattedtime1 = "$($time.hours):$($time.minutes):$("{0:n3}" -f$($time.totalseconds))"
$formattedtime2 = "{0:h:m:s.fff}" -f $time
$time
$formattedtime1
$formattedtime2
i suspect 10-15% of aec industry still on windowsxp , ie 6. it's sad, true.
anyway, got working formatting isn't tight , elegant, works. ;)
[string]$timestring = " [$($time.hours):$($time.minutes):$("{0:n3}" -f ($time.seconds + $time.milliseconds/1000))]"
thanks!
Windows Server > Windows PowerShell
Comments
Post a Comment