我需要一个城市到时区的映射列表 - 获得它的最佳方式? [英] I need a mapping list of cities to timezones- best way to get it?

查看:17
本文介绍了我需要一个城市到时区的映射列表 - 获得它的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个城市、州/省和国家/地区的列表,我需要轻松找到它们各自的时区.具体来说,我需要知道它们映射到哪个 Windows 时区.到目前为止,这是一个困难的过程,因为没有简单的方法可以将城市传递给某物并返回时区(时区是偏移量以及时区是否支持夏令时).

I have a list of cities, states/provinces, and countries and I need to find their respective timezones easily. Specifically, I need to know which Windows TimeZone they map to. So far this has been a difficult process, because there's no easy way to pass a city to something and get a timezone back (a timezone being an offset and whether or not the timezone supports Daylight Savings Time).

目前的流程是使用http://www.batchgeocode.com 获取经纬度城市(真正调用 Yahoo 服务),然后调用 http://www.EarthTools.org 以获取时区字母,映射到偏移量.问题是雅虎服务有时会返回错误的经度/纬度,并且 earthtools.org 对 DST 信息了解不多,因此映射到正确的时区 ID 是一个繁琐的手动过程.

The current flow is to use http://www.batchgeocode.com to get the latitude/longitude of the city (which really calls a Yahoo service) and then call http://www.EarthTools.org to get a timezone letter, which maps to an offset. The problem is the yahoo service will sometimes return a bad longitude/latitude, and earthtools.org doesn't know a lot about DST info so mapping to the correct TimeZone Id is a tedious manual process.

我不可能是第一个这样做的人 - 有没有人知道更好的方法,或者有一些包含我需要的信息的列表?

I can't be the first person who has done this- does anybody know of a better way, or some list out there which has the info I need?

谢谢.

推荐答案

有趣的问题!其他三个 SO 帖子(4150455901237023) 提到了几个潜在客户.有 Olson 数据库(请参阅 维基百科条目 用于描述),但它看起来更算法化/程序化(例如,如果你知道一个县名,印第安纳州).

Interesting question! These other three SO posts (41504, 55901 and 237023) mention a couple of leads. There's the Olson database (see the Wikipedia entry for description), but it looks more algorithmic/programmatic (e.g. if you know a county name, there's a rule for it for certain counties in Indiana).

我尝试查看 EarthTools,但它失败 St.Pierre/Miquelon,很好的测试用例之一(-3:00 而不是附近纽芬兰的 -3:30,这就是 EarthTools 所说的).

I tried looking at EarthTools but it failed for St.Pierre/Miquelon, one of the good test cases (-3:00 rather the -3:30 for nearby Newfoundland which is what EarthTools says).

一些有前途的选择:worldtimeengine.com 有一个免费的交互式版本和一个看起来很便宜的 API(5000 次查询每英镑),但 API 仅涵盖经纬度查询作为输入(而不是位置作为输入,这是交互式版本所具有的).

Some promising options: worldtimeengine.com has a free interactive version and an API which appears to be inexpensive (5000 queries per British pound), but the API only covers lat,long queries as inputs (not location as input, which is something the interactive version has).

最佳领导:我会看看 geonames.org 看起来它有一个很好的丰富的 API 可供您使用,而且它们有免费(慢)版本和商业版本以获得更好的性能.

Best lead: I'd look at geonames.org which looks like it has a nice rich API that you could use, and they have both a free (slow) version, and a commercial version for better performance.

附言这里有一些很好的测试用例(来自 worldtimezone.com维基百科的时区列表时区地图 也是说明性的):

p.s. here are some good test cases (from worldtimezone.com and Wikipedia's list of timezones, the map of time zones is also illustrative):

  • 委内瑞拉加拉加斯 (-4:30)
  • 纽芬兰甘德 (-3:30)
  • 伊朗德黑兰 (+3:30)
  • 阿富汗喀布尔 (+4:30)
  • 尼泊尔加德满都 (+5:45)
  • 缅甸仰光 (+6:30)
  • 新西兰查塔姆群岛 (+12:45)
  • 复活节岛 (-6)
  • 圣.皮埃尔和密克隆 (-3)
  • 福克兰群岛斯坦利 (-4)
  • 印第安纳州埃文斯维尔(-6=中部)
  • 俄勒冈州安大略省(-7=山区)

这篇关于我需要一个城市到时区的映射列表 - 获得它的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆