问题描述
我一直试图找到一种获取Windows批处理文件以在运行时显示当前UTC时间的方法.换句话说,就是获得自1970年启动以来的当前毫秒数.
I have been trying to find a way of getting a windows batch file to display the current UTC time when run. So in other words get the current amount of milliseconds since it was initiated in 1970.
有人知道该怎么做.
推荐答案
使用WMI:
for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr "="') do set %%x
这将设置您可以使用的变量Day
,DayofWeek
,Hour
,Minute
,Month
,Quarter
,Second
,WeekInMonth
和Year
.
This will set the variables Day
, DayofWeek
, Hour
, Minute
, Month
, Quarter
, Second
, WeekInMonth
and Year
which you can use, then.
尽管如此,您不会从Windows轻松地体验Unix时代.如果您拥有PowerShell,则可以使用
You won't get a time with Unix epoch from Windows easily, though. If you have PowerShell you can use
[long]((date).touniversaltime()-[datetime]'1970-01-01').totalmilliseconds
您可以通过以下方式从批处理文件中调用
which you can call from a batchfile via
powershell "..."
但是在那种情况下,您仍然可以用一种真实的语言编写批处理文件.
But in that case you could write your batch file in a real language anyway.
这篇关于如何使用Windows批处理文件获取UTC时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!