简体   繁体   English

我如何匹配从Api获得的timeZone名称和在C#中由系统查找的timeZone名称

[英]how i can match timeZone name which is obtain from Api and timeZone name find by system in C#

After passing latitude =-17.6509195 and long=-149.42604210000002 in time zone API. 在时区API中传递纬度= -17.6509195和long = -149.42604210000002之后。 I got Time Zone Name = " Tahiti " Time but when I pass this Time Zone Name in the C# method. 我得到了时区名称=“ Tahiti ”时间,但是当我在C#方法中传递此时区名称时。

Time Zone Info . 时区信息。 Find System Time Zone By Id(Time Zone Name); 通过ID(时区名称)查找系统时区;

It show an Exception : 它显示一个异常:

 "The time zone ID 'Tahiti Time' was not found on the local computer."

so how can I resolve this exception. 所以我该如何解决这个异常。

TimeZoneInfo.FindSystemTimeZoneById expects a standard name like "China Standard Time", the time zone name "Tahiti" is not a standard name. TimeZoneInfo.FindSystemTimeZoneById需要标准名称,例如“中国标准时间”,时区名称“ Tahiti”不是标准名称。 You can do a partial match against the standard name, though. 不过,您可以对标准名称进行部分匹配。 Like this 像这样

ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();

foreach (TimeZoneInfo timeZone in timeZones)
{
    if (timeZone.StandardName.Contains("Tahiti"))
    {
        //You have got the timezone
        break;
    }
}

By the way, I try to get all the time zones on Windows 10 (1703), and I find there is no Tahiti timezone, Tahiti seems to belong to Pacific Timezone. 顺便说一句,我尝试获取Windows 10(1703)上的所有时区,但我发现没有Tahiti时区,大溪地似乎属于太平洋时区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM