如何在 CLI 中顯示目前 Windows 作業系統日期、時間和時區?

如何在 CLI 中顯示目前 Windows 作業系統日期、時間和時區?

在Linux中,列印日期、時間和時區可以透過date命令輕鬆完成

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

-4時間之前和年份之前代表時區 (-4)。

這是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

>>> 

我想知道如何使用本機 Windows 命令在 Windows 作業系統上執行相同的操作?

echo %date%-%time%命令只能產生星期、日期、時間。但是時區不存在。

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

C:\>

我期待的是這樣的事情。

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

C:\>

或者

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

C:\>

答案1

您可以使用它來輸出當前日期、時間和時區:

echo %date% %time% & tzutil /g

或者,如果您想在一行中輸出它們:

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

請注意,如果您要將它們放入批次檔中,則需要變更%i為。%%i

相關內容