如何使用 PowerShell 运行时区?


要获取系统的时区,可以使用 Get-TimeZone 命令。

示例

PS C:\> Get-TimeZone

Id                         : Mountain Standard Time
DisplayName                : (UTC-07:00) Mountain Time (US & Canada)
StandardName               : Mountain Standard Time
DaylightName               : Mountain Daylight Time
BaseUtcOffset              : -07:00:00
SupportsDaylightSavingTime : True

要设置系统的时区,可以使用时区的 ID 或名称。

示例

PS C:\> Set-TimeZone -Id "Pacific Standard Time" -PassThru
Id                         : Pacific Standard Time
DisplayName                : (UTC-08:00) Pacific Time (US & Canada)
StandardName               : Pacific Standard Time
DaylightName               : Pacific Daylight Time
BaseUtcOffset              : -08:00:00
SupportsDaylightSavingTime : True

要检索所有可用时区的列表,我们需要使用 System.TimeZoneInfo .net 类和 GetSystemTimeZones() 方法。

[System.TimeZoneInfo]::GetSystemTimeZones() |ft -AutoSize

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

输出

更新于:2020-11-09

879 次浏览

开启你的 职业生涯

完成课程获取认证

开始入门
广告