Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get system time accurate to milliseconds in Windows cmd

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.

like image 314
Yabasa Avatar asked Oct 30 '22 07:10

Yabasa


1 Answers

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)"
like image 121
Yabasa Avatar answered Nov 15 '22 06:11

Yabasa