2

Such city-based time zones (or whatever you call this) as Asia/Shanghai, America/Los_Angeles are widely used in PHP and Java, for example,

java.util.TimeZone.TimeZone timeZoneNewYork = java.util.TimeZone.TimeZone.getTimeZone("America/New_York");

As far as I know, .Net uses a different key to get the corresponding time zone, for America/New_York it's Eastern Standard Time

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

If I have a city-based time zone string, e.g. "America/New_York", how can I convert it to the right time zone in .Net, TimeZoneInfo{Eastern Standard Time}

Peter O.
  • 32,158
  • 14
  • 82
  • 96
S.831
  • 113
  • 1
  • 10

1 Answers1

1

Those are IANA/Olson time zone identifiers, and they are much more universal than the Windows time zones that .Net uses. Read the "Time Zone Databases" section of the timezone tag wiki.

There are several libraries that you can use to work with these in .Net, but the best one IMHO is Noda Time. With this library, you won't need to use TimeZoneInfo at all.

Update

I have posted conversion functions here.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575