Get timezone from windows command line

Query the time zone from the command line I want to print the a bottom line with the echo command

this is my try but i get the error

@echo off
set a="tzutil /g"
echo %a%
exit

please help

6

2 Answers

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

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like