How-to: Calculate Greenwich Mean Time - GMT.cmd

Display the current date and time adjusted to Greenwich Mean Time, this can be useful when comparing events across multiple time zones.

The WMIC tool is deprecated in Windows 10, version 21H1 and the 21H1 semi-annual channel release of Windows Server.
In PowerShell, this can be done with just: (Get-Date).ToUniversalTime()


::gmt.cmd  Display the current date and time in GMT (World Time)
@echo off
Setlocal EnableDelayedExpansion
call :get_local_time
call :get_utc_time

:: Add leading zeros
Set gmt_minute=0%gmt_minute%
Set gmt_minute=%gmt_minute:~-2%
Set gmt_day=0%gmt_day%
Set gmt_day=%gmt_day:~-2%
Set gmt_month=0%gmt_month%
Set gmt_month=%gmt_month:~-2%
Set local_minute=0%local_minute%
Set local_minute=%local_minute:~-2%
Set local_day=0%local_day%
Set local_day=%local_day:~-2%
Set local_month=0%local_month%
Set local_month=%local_month:~-2%

:: Display result
Echo     GMT Date/Time: %gmt_year%-%gmt_month%-%gmt_day% %gmt_hour%:%gmt_minute%
Echo   Local Date/Time: %local_year%-%local_month%-%local_day% %local_hour%:%local_minute%
goto :eof

for /f "tokens=1,2 delims==" %%G in ('WMIC path Win32_LocalTime get /value ^| find "="') do (call :setVars %%G %%H)
goto :eof

   Set _var=%1
   Set _value=%2
   Set local_!_var!=!_value!
goto :eof

for /f "tokens=1,2 delims==" %%G in ('WMIC path Win32_UTCTime get /value ^| find "="') do (call :setUTCvars %%G %%H)
goto :eof

   Set _var=%1
   Set _value=%2
   Set gmt_!_var!=!_value!
goto :eof

“Time is like money, the less we have of it to spare, the further we make it go” ~ Josh Billings

Related commands

datetime.vbs - Get Date, Time and daylight savings (VB Script).
GetTime.cmd - Get the time now.
TIME - Set the time (list of default time formats for different countries).
Rob Vanderwoude - date/time scripts.

Copyright © 1999-2023
Some rights reserved