如何使用Windows批处理文件获取UTC时间 [英] How to get UTC time with windows batch file

查看:291
本文介绍了如何使用Windows批处理文件获取UTC时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图找到一种获取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

这将设置您可以使用的变量DayDayofWeekHourMinuteMonthQuarterSecondWeekInMonthYear.

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时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆