在Windows cmd中获取精确到毫秒的系统时间 [英] Get system time accurate to milliseconds in Windows cmd
问题描述
我正在尝试使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
任何帮助将不胜感激.
推荐答案
正如Neil指出的那样,cmd中没有本机解决方案.对于可以选择使用PowerShell的任何人,您可以使用以下内容:
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.
由于问题被标记为 cmd
,因此从cmd调用此命令的适当命令行为:
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)"
这篇关于在Windows cmd中获取精确到毫秒的系统时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!