Thursday 8 March 2018

How to display current Windows OS date, time and timezone in CLI?


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:\> 
Sun Mar 10 11:51:55 -04 2018

C:\>

or


C:\> 
Date: 11 March 2018, 00:05:50 EST

C:\>

Answer



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.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...