I am aware that one can print batch time up to the centisecond with @echo %time%. Is there a way to get milliseconds with precision of 3 and leading zero in hrs as well? E.g 06:58:30.483
%time% prints without leading zero in hrs and with 2 fraction in ms E.g 6:58:25.25
CodePudding user response:
Because I'd assume it is much faster than wmic or powershell, here's a batch-file with a vbscript wsh helper:
<!-- ::Script Language="Batch"
@For /F %%G In ('%SystemRoot%\System32\cscript.exe //NoLogo "%~f0?.wsf"')Do @Echo(%%G
@Pause&Exit /B
--><Job><Script Language="VBScript">
t0=Timer():t1=Time():t2=Int(t0):t0=FormatNumber(t0,2)
ms=Left(Split(t0,",")(1)&"0",3):h1=Hour(t1):m1=r2(Minute(t1))
s1=r2(Second(t1)):h2=div(3600,t2):m2=r2(div(60,t2)):s2=r2(t2)
WScript.Echo h2&":"&m2&":"&s2&"."&ms
Function r2(s):r2=right("0"&s,2):End Function
Function div(divisor, byref val):div=val\divisor:val=val MOD divisor
End Function</Script></Job>
CodePudding user response:
If you are on a supported windows
system, you already have a program that will produce what you want using a batch-file
running under cmd
.
FOR /F "delims=" %%A IN ('powershell.exe -NoLogo -NoProfile -Command "Get-Date -Format HH:mm:ss.fff"') DO (SET "THETIME=%%~A")
ECHO THETIME is %THETIME%