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              : 0
hours             : 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

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Event ID 64,77,1008 Certificates Events Windows Server 2008, 2008R2