4

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 2

2

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

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .