windows 如何从命令行设置时区?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16656229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I set the timezone from command line ?
提问by Eduard Florinescu
How can I set the timezone in Windows from command line or from a batch file?
如何从命令行或批处理文件在 Windows 中设置时区?
Do I need to use powershell or cscript?
我需要使用 powershell 或 cscript 吗?
回答by Ionic? Biz?u
The command line utility that helps you change the time zone in Windows 7 is tzutil.exe
and is known as Windows Time Zone Utility. This is a great tool for all the people who prefer working from the command prompt.
帮助您在 Windows 7 中更改时区的命令行实用程序tzutil.exe
称为Windows 时区实用程序。对于所有喜欢在命令提示符下工作的人来说,这是一个很好的工具。
Use the /s
parameter to setthe time zone:
使用/s
参数设置时区:
tzutil /s "universal standard time"
Use the /g
parameter to getthe time zone:
使用/g
参数获取时区:
tzutil /g
Use the /l
parameter to listthe valid time zones.
使用该/l
参数列出有效的时区。
tzutil /l
回答by Christian Geiselmann
If anyone still uses Windows XP (as I do):
如果有人仍然使用 Windows XP(就像我一样):
Step 1:
第1步:
You can use the following command line, e.g. in the "Execute" window (cmd):
您可以使用以下命令行,例如在“执行”窗口 (cmd) 中:
Control.exe TIMEDATE.CPL,,/Z W. Europe Standard Time
Where "W. Europe Standard Time" is, not really surprisingly, for Western Europe. Other possible values are e.g.
“西欧标准时间”对于西欧来说并不奇怪。其他可能的值是例如
- E. Europe Standard Time (for Eastern Europe)
- Pazifik Standard Time (for what it says)
- E. 欧洲标准时间(东欧)
- Pazifik 标准时间(它所说的)
and so on. A list of possible values can be found here (although for Windows Vista, but it seems most values are the same):
等等。可以在此处找到可能值的列表(虽然对于 Windows Vista,但似乎大多数值都相同):
https://technet.microsoft.com/en-us/library/cc749073%28v=ws.10%29.aspx
https://technet.microsoft.com/en-us/library/cc749073%28v=ws.10%29.aspx
Step 2
第2步
In order to run the above command from a shortcut, you can do the following:
为了从快捷方式运行上述命令,您可以执行以下操作:
Create a new shortcut (e.g. in Windows explorer, right-click anywhere in an empty area, and choose "New shortcut") and give it the following value (by entering the code into the window that opens, or as "target" in the accordingly named field):
创建一个新的快捷方式(例如在 Windows 资源管理器中,右键单击空白区域的任意位置,然后选择“新建快捷方式”)并为其指定以下值(通过在打开的窗口中输入代码,或在相应命名的字段):
C:\Windows\System32\cmd.exe /c Control.exe TIMEDATE.CPL,,/Z W. Europe Standard Time
(The example uses W. Europe Standard Time; change this to your liking)
(该示例使用西欧标准时间;根据您的喜好进行更改)
Calling this shortcut (i.e. clicking the Icon) immediately changes the timezone.
调用此快捷方式(即单击图标)会立即更改时区。
For my needs, I created two such shortcuts, one setting the timezone to Western Europe, the other setting it to Eastern Europe, as these are the locations where I am working regularly.
根据我的需要,我创建了两个这样的快捷方式,一个将时区设置为西欧,另一个将其设置为东欧,因为这些是我经常工作的地方。
(Source for Step 2: Run a Command Prompt command from Desktop Shortcut)
(第 2 步的来源:从桌面快捷方式运行命令提示符命令)
回答by Kame House
If you have PowerShell 5.1, you have the equivalent of tzutil in PowerShell. For example, if you have Windows 10.
如果您有 PowerShell 5.1,则您在 PowerShell 中拥有与 tzutil 等效的功能。例如,如果您有 Windows 10。
Examples:
例子:
See current time zone:
查看当前时区:
Get-TimeZone
See available time zones:
查看可用时区:
Get-TimeZone -ListAvailable
Set a time zone:
设置时区:
Set-TimeZone -Name "Georgian Standard Time"
Source: https://www.sysadmit.com/2019/08/cambiar-zona-horaria-Windows.html
来源:https: //www.sysadmit.com/2019/08/cambiar-zona-horaria-Windows.html
回答by Christian Geiselmann
Here is another answer to the initial question, related to Windows 7. This solution is completely based on Ionica Bizau's first contribution (see above). Essentially, I just added a step-by-step instruction for creating a batch file.
这是与 Windows 7 相关的初始问题的另一个答案。该解决方案完全基于 Ionica Bizau 的第一个贡献(见上文)。本质上,我只是添加了创建批处理文件的分步说明。
To create a batch file for setting time zones:
创建用于设置时区的批处理文件:
1) Create a text file in any text editor (PSPad, Notepad++, Notepad or whatever)
1) 在任何文本编辑器(PSPad、Notepad++、Notepad 或其他)中创建一个文本文件
2) In the text file, write just one line of code. E.g. write
2) 在文本文件中,只写一行代码。例如写
tzutil /s "GTB Standard Time"
which will set the time zone for Sofia, Bucharest, etc. Or use
这将设置索非亚、布加勒斯特等的时区。或者使用
tzutil /s "W. Europe Standard Time"
for places in the geographical longitudes of Amsterdam, Brussels, etc.
位于阿姆斯特丹、布鲁塞尔等地理经度的地方。
3) Save the file with a meaningful name such as "Set_TimeZone_W-Europe.bat". Make sure that the filetype suffix is ".bat". Save it at any place you like in your file system. You may choose your "Desktop" folder so to make the file available from your desktop screen.
3) 使用有意义的名称保存文件,例如“Set_TimeZone_W-Europe.bat”。确保文件类型后缀为“.bat”。将其保存在文件系统中您喜欢的任何位置。您可以选择“桌面”文件夹,以便在桌面屏幕上提供该文件。
4) That's it. Double-clicking the icon will trigger the (minimalistic) programme code to be executed, i.e. the system time will be set as desired.
4)就是这样。双击图标将触发(简约)程序代码执行,即系统时间将根据需要设置。
Note: For my purposes, I made two such files, one for Western Europe, one for South East Europe, which are places I visit regularly.
注意:为了我的目的,我制作了两个这样的文件,一个是西欧,一个是东南欧,这是我经常去的地方。
If you need other time zones, look them up how they are named as follows:
如果您需要其他时区,请查看它们的命名方式,如下所示:
a) Open the "Execute" window (cmd)
a) 打开“执行”窗口(cmd)
b) Type "tzutil /l" (without the quotation marks) and hit "return". This will display a list of available time zones.
b) 输入“tzutil /l”(不带引号)并点击“return”。这将显示可用时区的列表。