简体   繁体   中英

Looking up timezone from region / coordinates

I would like to look up a timezone based on an ISO region code or coordinates.

I have a collection of data points with coordinates, county and region codes, eg:

33.942501,-118.407997,"US","US-CA"

I want to find the IANA timezone identifier, eg. America/Los_Angeles , based on the above info.

Is it possible to do that with NodaTime ? I cannot see a way to look up DateTimeZone or timezone identifier from a region code or location.

The GeoTimeZone NuGet package can provide a lookup by lat/long to IANA ID, and then you can use DateTimeZoneProviders.Tzdb[id] to get the DateTimeZone from that. See the project home page for more details.

Within Noda Time itself, you can use TzdbDateTimeZoneSource.Default (or one that you've loaded) and then the ZoneLocations or Zone1970Locations properties to find zones for specific ISO-3166 countries... but they doesn't go below the "country" level (although they do have exemplar lat/long values). They're based on zone.tab and zone1970.tab - so any information not in that file isn't present in Noda Time either.

It sounds like GeoTimeZone is probably your best option here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM