0

I am using method to get timezone from TimeZoneId

var timezoneObject= TimeZoneInfo.FindSystemTimeZoneById("UTC");

What I am expecting as

timezoneObject.Id : UTC
timezoneObject.DisplayName :(UTC) Coordinated Universal Time
timezoneObject.StandardName: Coordinated Universal Time
timezoneObject.DaylightName: Coordinated Universal Time

but I am getting result as

timezoneObject.Id : UTC
timezoneObject.DisplayName :UTC
timezoneObject.StandardName: UTC
timezoneObject.DaylightName: UTC

But in case of

var timezoneObject= TimeZoneInfo.FindSystemTimeZoneById("Dateline Standard Time"); 

its giving desired output.

1
  • 1
    Timezone info comes from the registry. Except for "UTC", that is intercepted early. The source code suggests that there might be Windows versions that don't have it in the registry. Not sure if that is accurate, I could however imagine programmers that solved their datetime problem by editing the registry :) Feature, not a bug. Jul 23, 2016 at 8:06

1 Answer 1

2

You'll get your desired result by using this method:

var timezoneObject = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(x=> x.Id == "UTC");

Ouput:

timezoneObject.Id : UTC
timezoneObject.DisplayName :(UTC) Coordinated Universal Time
timezoneObject.StandardName: Coordinated Universal Time
timezoneObject.DaylightName: Coordinated Universal Time

From Docs:

The id parameter must correspond exactly to the time zone's registry key in length, but not in case, for a successful match to occur; that is, the comparison of id with time zone identifiers is case-insensitive. If you want to retrieve time zone objects based on partial matches, you can write custom procedures that work with the read-only collection of TimeZoneInfo objects returned by the GetSystemTimeZones method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.