GMT.cmd

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

::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

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

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

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

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

Alternatives:
In PowerShell, this can be done with just:

 $mydtm = Get-Date
 $mydtm.ToUniversalTime()

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

Related

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 © SS64.com 1999-2018
Some rights reserved