Returns the current time into the variable %_gmt% adjusted to Greenwich Mean Time, this can be useful when comparing events across multiple time zones or whenever you don’t want daylight savings to affect the result.
::gmt.cmd Display the current time in GMT (World Time)
@echo off
Setlocal
Set _key=HKLM\System\CurrentControlSet\Control\TimeZoneInformation
:: find offset from GMT in minutes
For /f "Tokens=3" %%G in ('Reg query %_key% /V ActiveTimeBias^|FIND "REG_DWORD"') do (
Set /a _offset=%%G
)
:: Convert to hours
Set /a _offset_hours=%_offset% / 60
:: Get current local time
For /f "tokens=1-3 delims=1234567890 " %%a in ("%time%") Do set "delims=%%a%%b%%c"
For /f "tokens=1-4 delims=%delims%" %%G in ("%time%") Do (
Set _hh=%%G
Set _min=%%H
)
:: Strip any leading spaces
Set _hh=%_hh: =%
:: Ensure the hours have a leading zero
if 1%_hh% LSS 20 set _hh=0%_hh%
Echo Local time: %_hh%:%_min%
:: add offset to the current time
Set /a _hh=%_hh% + %_offset_hours%
:: display result
Echo GMT time: %_hh%:%_min%
ENDLOCAL&Set _gmt=%_hh%:%_min%
“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-2013
Some rights reserved