11

SO I am new to NodaTime and trying to use it to for storing timezone information using DateTimeZone object.

I came across below sample in user guide etc. which give me a nice DateTimeZone object from tzdb, which is great.

var london = DateTimeZoneProviders.Tzdb["Europe/London"];

My question is - how do I get a list of timezone strings ("Europe/London") which are used in the tzdb. I looked around, nowhere to find. Is there a standard list somewhere which I can refer to? How does this work? ex. - what is the string I should pass for EST?

Thanks!

Abhishek
  • 478
  • 6
  • 16

1 Answers1

17

To fetch the time zone IDs programmatically, use the Ids property in IDateTimeZoneProvider. For example, to find all zones:

var provider = DateTimeZoneProviders.Tzdb;
foreach (var id in provider.Ids)
{
    var zone = provider[id];
    // Use the zone 
}

For Eastern Time, you probably want America/New_York.

More generally, these identifiers are the ones from IANA - and they're the ones used in most non-Windows systems.

dahlbyk
  • 75,175
  • 8
  • 100
  • 122
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • @EndyTjahjono: That's got the raw time zone data. I don't know of any very simple way to get all the IDs from there without a lot of other data. – Jon Skeet Jan 05 '18 at 11:51