C:\_G\WWW\~ELISANET\INFO\tscmd143.html
<http://www.elisanet.fi/tsalmi/info/tscmd143.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Tue 20-Nov-2018 14:48:29

 
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
  C:\_D\TEST>cmdfaq
  Bias: -120 minutes
  UTC+(2.0)

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.
  C:\_D\TEST>cmdfaq
  (GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius
  GMT+02:00

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
  C:\_D\TEST>cmdfaq
  TZbias=-180

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
  C:\_D\TEST>cmdfaq
  TZbias=120
  TZdaylightbBias=-60

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]

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd143.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd143
http://www.elisanet.fi/tsalmi/info/tscmd143.html
file:///c:/_g/www/~elisanet/info/tscmd143.html