Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the list of strings in tzdb used as time zone initializer?

Tags:

nodatime

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!

like image 937
Abhishek Avatar asked Aug 19 '15 19:08

Abhishek


1 Answers

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.

like image 128
Jon Skeet Avatar answered Oct 19 '22 13:10

Jon Skeet