powershell - 将字符串转换为特定的日期时间/时区

标签 powershell datetime timezone

使用 Powershell,如何将此字符串转换为美国东部/时间并仅使用格式 HH:mm:ss 显示时间?

Thu, 30 Nov 2023 17:50:51 GMT

感谢任何帮助,谢谢!

最佳答案

您可以使用TimeZoneInfo.ConvertTimeBySystemTimeZoneId Method :

[System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId(
    [System.DateTimeOffset] 'Thu, 30 Nov 2023 17:50:51 GMT',
    'Eastern Standard Time').
    ToString('HH:mm:ss')

此外,当您不确定应该为 destinationTimeZoneId 参数使用的 Id 是什么时,您可以使用:

[System.TimeZoneInfo]::GetSystemTimeZones() |
    Select-Object DisplayName, Id, BaseUtcOffset

关于powershell - 将字符串转换为特定的日期时间/时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77585928/

相关文章:

powershell - 在 Powershell 中,如何获取本地 zip 文件的 Base64 编码内存流?

powershell - Start-Job 输出去哪里了?

powershell - 如何将参数从 C# 传递到 PowerShell 脚本文件?

c - linux 将时间(针对不同的时区)转换为 UTC

azure - 通过 Powershell 在 EA 门户中激活服务主体作为帐户所有者?

sql - 从 Now() 到 Postgresql 中的 Current_timestamp

javascript:获取印度的日期和时间(不是个人计算机的日期和时间)

javascript - 如何使用两个日期的 getTime() 正确计算 JS 中的剩余时间?

php - 时区正确,但时间不正确 - PHP MySQL

java - 从字符串转换为日期对象不显示预期结果