I'm trying to get the system time accurate to milliseconds in Windows cmd. I know that it's possible to get centisecond accuracy using:
echo %time%
I've found other questions that are asking the exact same thing but there is no answer that fully answers the question. Here is what I've found so far:
This solution is only good for centisecond accuracy (same as what I described above): Print time in a batch file (milliseconds)
This solution provides a timer solution but not a print current timestamp solution: Print Batch Time in Milliseconds
Any help would be much appreciated.
As Neil pointed out there is no native solution in cmd. For anyone who has the option of using PowerShell instead, you could use the following:
(Get-Date -UFormat "%Y-%m-%d %H:%M:%S").toString() + "." + ((Get-Date).millisecond)
There may be a more succinct way of doing it but this worked for my purposes.
Since the question is tagged cmd
the appropriate command line for calling this from cmd is:
powershell -command "(Get-Date -UFormat '%Y-%m-%d %H:%M:%S').toString() + '.' + ((Get-Date).millisecond)"
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