Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Thu 22-Apr-2010 17:48:00

Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.

143} How do I get the current time zone in a script?

  @echo off & setlocal enableextensions
  :: Get the time zone in minutes

  for /f "tokens=5" %%a in (
    'w32tm /tz^|find "Time zone"') do set TZbias=%%a
  for /f "tokens=1 delims=m" %%a in (
    'echo %TZbias%') do set TZbias=%%a
  :: Display the result in minutes

  echo Bias: %TZbias% minutes
  :: Display the result in hours

  set /a TZfrac=%TZbias%%%60*100/60
  if %TZfrac% LSS 0 set /a TZfrac=-%TZfrac%
  set /a TZbias=-%TZbias%/60
  echo UTC+(%TZbias%.%TZfrac%)
  endlocal & goto :EOF
The output for my own computer's time zone (Europe/Helsinki) is
  Bias: -120 minutes

Alternatively, in XP and beyond
  @echo off & setlocal enableextensions
  for /f "tokens=* skip=1" %%i in ('wmic OS Get CurrentTimeZone') do (
    set CurrentTimeZone_=%%i)
  echo CurrentTimeZone: %CurrentTimeZone_% minutes
  endlocal & goto :EOF
The output for my own computer's time zone (Europe/Helsinki) in the summer is
  C:\_D\TEST>cmdfaq   CurrentTimeZone: 180               minutes

Another method:
  @echo off & setlocal enableextensions
  for /f "tokens=2,*" %%i in ('systeminfo^|findstr /b "Time Zone:"') do (
    set tz_=%%j)
  echo %tz_%
  for /f "tokens=1" %%i in ('echo "%tz_%"') do set tz_=%%~i
  set tz_=%tz_:(=%
  set tz_=%tz_:)=%
  echo %tz_%
  endlocal & goto :EOF
The output might be e.g.
  (GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius

Using JavaScript in WSH
  @echo off & setlocal enableextensions
  set js_=%temp%\tmp$$$.js
  >"%js_%" echo WScript.Echo(new Date().getTimezoneOffset());
  for /f %%a in ('cscript //nologo "%js_%"') do (
    set TZbias=%%a)
  for %%f in ("%js_%") do if exist %%f del "%%f"
  echo TZbias=%TZbias%
  endlocal & goto :EOF
The output for my own computer's time zone (Europe/Helsinki) in the summer is

A Visual Basic Script (VBScript) aided command line script solution
  @echo off & setlocal enableextensions
  :: Build a Visual Basic Script and run it

  set vbs_=%temp%\tmp$$$.vbs
  set skip=
  findstr "'%skip%VBS" "%~f0" > "%vbs_%"
  for /f "tokens=1-2" %%a in ('cscript //nologo "%vbs_%"') do (
    set TZbias=%%a
    set TZdaylightBias=%%b)
  :: Clean up

  for %%f in ("%vbs_%") do if exist %%f del %%f
  :: Display the time zone offsets from Greenwich mean time

  echo TZbias=%TZbias%
  echo TZdaylightBias=%TZdaylightBias%
  endlocal & goto :EOF
  'The Visual Basic Script 'VBS

  Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 'VBS
  Set colTimeZone = objWMIService.ExecQuery("Select * from Win32_TimeZone") 'VBS
  For Each objTimeZone in colTimeZone 'VBS
    Wscript.Echo objTimeZone.Bias & " " & objTimeZone.DaylightBias 'VBS
  Next 'VBS
The output for my own computer's time zone (Europe/Helsinki) in the summer is

Caveat: The item delves into whatever information the XP computer offers under the hood. The interpretation of the terminology and the usage of the results is up to the user, since mine is a scripting FAQ, not a calendar intricacies treatise.

References/Comments: (If a Google message link fails try the links within the brackets.)
  W32tm.exe: Windows Time
  MS-DOS Batch Files J R Stockton
  Dates and Times Microsoft TechNet Script Repository
  Google Groups Apr 26 2009, 10:39 pm [M]