Get timezone from windows command line

If you want to echo the time zone, all you need is:

@echo off

tzutil /g
echo.

pause

Unless you want to have quotes inside your variable, you want to put them before and after your set options like this: set "zone=tzutil /g" instead of having your first double quote after the equals sign. If your goal is to set the output of tzutil /g as a variable, you would do it like this:

@echo off

for /f "tokens=* usebackq" %%A in (`tzutil /g`) do (
    set "zone=%%A"
)

echo %zone%

pause

Here you use for /f to loop through the output of a command, then set your variable using the parameter.

Reference: tzutil, For /f


How can I print the timezone from a batch file using echo?

Use the following batch file (test.cmd):

@echo off
setlocal
for /f "tokens=*" %%f in ('tzutil /g') do (
  echo %%f
  )
endlocal

Example usage:

F:\test>test
GMT Standard Time

F:\test>

Further Reading

  • An A-Z Index of the Windows CMD command line | SS64.com
  • Windows CMD Commands (categorized) - Windows CMD - SS64.com
  • For /f- Loop through command output - Windows CMD - SS64.com
  • tzutil - Windows CMD - SS64.com