2

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.

| improve this question | |
  • 5
    1970 has nothing to do with UTC. 1970-01-01 is the Unix time epoch and Unix time uses UTC, but apart from that the two are completely unrelated. – Joey Mar 26 '12 at 12:28
10

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.