7

In Linux, printing out date, time, and timezone can be easily accomplished with date command

[user@linux ~]$ date
Sun Mar 10 11:51:55 -04 2018
[user@linux ~]$ 

-4 before after the time and before the year represents timezone (-4).

This is in Python ....

[user@linux ~]$ python
Python 2.7.5 (default, May  3 2017, 07:55:04) 
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import time
>>> print (time.strftime("\n Date: %d %B %Y, %H:%M:%S %Z\n"))

 Date: 11 March 2018, 00:05:50 EST

>>> 

I was wondering how to perform the same thing on Windows OS using native windows command?

echo %date%-%time% command can only produce day, date, dan time. However timezone is not there.

C:\> echo  %date%-%time%
 Sun 03/10/2018-11:56:05.31

C:\>

What I'm expecting is something like this.

C:\> <some windows command>
 Sun Mar 10 11:51:55 -04 2018

C:\>

or

C:\> <some windows command>
Date: 11 March 2018, 00:05:50 EST

C:\>
2

1 Answer 1

21

You can use this to output the current date, time, and time zone:

echo %date% %time% & tzutil /g

Or if you want to output them in a single line:

for /f "tokens=*" %i in ('tzutil /g') do echo %date% %time% %i

Take note that you need to change %i to %%i if you want to put them in a batch file.

You must log in to answer this question.

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