c# - 如何按名称查找 TimeZoneInfo

标签 c#

我知道我们可以使用 id 查找时区信息

TimeZoneInfo timeZone2 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

有什么我们可以用名字来获取的东西吗?

example: 
TimeZoneInfo timeZone2 = TimeZoneInfo.FindSystemTimeZoneByName("(UTC-12:00) International Date Line West");

没有像这样的内置方法。

最佳答案

您显示的名称是显示名称。一个简单的 linq 查询可以为您带来。

string displayName = "(UTC-12:00) International Date Line West";
var tz = TimeZoneInfo.GetSystemTimeZones()
    .FirstOrDefault(x => x.DisplayName == displayName);

关于c# - 如何按名称查找 TimeZoneInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23423851/

相关文章:

c# - Visual Studio Code IntelliSense 建议不会自动弹出

c# - 登录后 Azure AD 卡在循环中

c# - 我在反序列化枚举时遇到问题

c# - BitConverter.ToString(hash).Replace ("-", string.Empty) 在 python 中等效?

c# - 简单的 HTTPS 到 PHP 脚本

c# - 字符串插值与 String.Format

c# - 如何写入文本文件中的下一行?

c# - IOC 和动态参数

c# - 使用 Oracle Managed Driver Core 的 asp.net core docker 容器。打开连接时抛出 ORA-00604 和 ORA-01882

c# - Linq方法获取列表中元素和下一个元素之间的分段差异