使用 PowerShell 設定時區
Rohan Timalsina
2023年1月30日
PowerShell
PowerShell Timezone
時區是使用相同標準時間的地理區域。必須在系統中設定正確的時區。你可以從日期和時間設定輕鬆設定或更改時區。
本教程將教你使用 PowerShell 設定時區。
在 PowerShell 中使用 Get-TimeZone 獲取時區
Get-TimeZone cmdlet 顯示系統上使用的當前時區。
Get-TimeZone
輸出:
Id : Nepal Standard Time
DisplayName : (UTC+05:45) Kathmandu
StandardName : Nepal Standard Time
DaylightName : Nepal Daylight Time
BaseUtcOffset : 05:45:00
SupportsDaylightSavingTime : False
-ListAvailable 引數列印所有可用時區的列表,你只能從輸出顯示的可用時區中設定時區。
Get-TimeZone -ListAvailable
在 PowerShell 中使用 Set-TimeZone 設定時區
Set-TimeZone cmdlet 將系統時區設定為給定時區。你可以使用 Id 或 Name 屬性設定時區。
通過 Id 設定時區。
Set-TimeZone -Id "Greenwich Standard Time"
它將系統時區設定為格林威治標準時間。
Get-TimeZone
輸出:
Id : Greenwich Standard Time
DisplayName : (UTC+00:00) Monrovia, Reykjavik
StandardName : Greenwich Standard Time
DaylightName : Greenwich Daylight Time
BaseUtcOffset : 00:00:00
SupportsDaylightSavingTime : False
通過 Name 設定時區。
-Name 引數必須與目標時區的 StandardName 或 DaylightName 屬性匹配。時區的 Id 和 Name 並不總是匹配。
Set-TimeZone -Name "Coordinated Universal Time"
它將系統時區設定為協調世界時。
Get-TimeZone
輸出:
Id : UTC
DisplayName : (UTC) Coordinated Universal Time
StandardName : Coordinated Universal Time
DaylightName : Coordinated Universal Time
BaseUtcOffset : 00:00:00
SupportsDaylightSavingTime : False
在 PowerShell 中使用 tzutil 設定時區
這是在 PowerShell 中設定時區的另一種方法。
/g 引數顯示系統的當前時區。
tzutil /g
它只顯示時區的 Id。
輸出:
UTC
/l 引數顯示所有可用時區 ID 的列表並顯示名稱。
tzutil /l
使用 /s 引數設定系統時區。它只需要一個引數,即時區 Id。
tzutil /s "Fiji Standard Time"
它將系統時區設定為斐濟標準時間。
tzutil /g
輸出:
Fiji Standard Time
這 /? 引數顯示終端的使用資訊。
tzutil /?
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
作者: Rohan Timalsina
