How to get UTC time with windows batch file

我只是一个虾纸丫 提交于 2019-12-06 11:04:24

问题


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.

Does anyone know how to do this.


回答1:


Using WMI:

for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr "="') do set %%x

This will set the variables Day, DayofWeek, Hour, Minute, Month, Quarter, Second, WeekInMonth and Year which you can use, then.

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.



来源:https://stackoverflow.com/questions/9871499/how-to-get-utc-time-with-windows-batch-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!