0

After passing latitude =-17.6509195 and long=-149.42604210000002 in time zone API. I got Time Zone Name = "Tahiti" Time but when I pass this Time Zone Name in the C# method.

Time Zone Info . Find System Time Zone By Id(Time Zone Name);

It show an Exception :

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

so how can I resolve this exception.

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • 2
    Possible duplicate of [TimeZone Not Found Exception](https://stackoverflow.com/questions/36838663/timezone-not-found-exception) – derloopkat Nov 11 '17 at 13:40

1 Answers1

0

TimeZoneInfo.FindSystemTimeZoneById expects a standard name like "China Standard Time", the time zone name "Tahiti" is not a standard name. 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.

kennyzx
  • 12,845
  • 6
  • 39
  • 83