如何通过名称查找TimeZoneInfo

本文关键字:查找 TimeZoneInfo 何通过 | 更新日期: 2023-09-27 18:01:31

我知道我们可以使用

通过id找到时区信息
TimeZoneInfo timeZone2 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

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

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

没有这样的内置方法

如何通过名称查找TimeZoneInfo

您显示的名称是显示名称。一个简单的linq查询就可以实现。

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