将美国邮政编码映射到时区 [英] Mapping US zip code to time zone

查看:39
本文介绍了将美国邮政编码映射到时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户注册我们的应用时,我们可以通过国家数据库验证他们的邮政编码.从这个邮政编码确定他们的时区的潜在猜测的最佳方法是什么?

When users register with our app, we are able to infer their zip code when we validate them against a national database. What would be the best way to determine a good potential guess of their time zone from this zip code?

我们正在努力尽量减少我们明确要求他们提供的数据量.如果我们的最佳猜测是错误的,他们将能够稍后手动设置时区.我意识到邮政编码无助于确定美国以外的时区,但在这种情况下,无论如何我们都必须手动询问,无论如何我们主要与美国打交道.

We are trying to minimize the amount of data we explicitly have to ask them for. They will be able to manually set the time zone later if our best guess is wrong. I realize zip codes won't help with figuring out the time zone outside the US, but in that case we'd have to manually ask anyway, and we deal predominantly with the US regardless.

我找到了很多邮政编码数据库,到目前为止只有少数包含时区信息,但那些不是免费的,例如 这个.如果绝对有必要为某项服务付费订阅才能执行此操作,那么这将不值得,我们只需明确询问用户即可.

I've found a lot of zip code databases, and so far only a few contain time zone information, but those that do are not free, such as this one. If it's absolutely necessary to pay a subscription to a service in order to do this, then it will not be worth it and we will just have to ask users explicitly.

尽管语言不是特别相关,因为我可能可以根据需要进行转换,但我们使用的是 PHP 和 MySQL.

Although language isn't particularly relevant as I can probably convert things however needed, we're using PHP and MySQL.

推荐答案

我刚刚找到了一个 免费 zip 数据库 包括时间偏移和参与 DST.我确实喜欢 Erik J 的回答,因为它可以帮助我选择实际时区,而不仅仅是偏移量(因为您永远无法完全确定规则),但我想我可以从这个开始,并尝试根据 offset/dst 配置找到最佳时区匹配.我想我可能会尝试设置一个简单版本的 Development 4.0 的答案,以检查我从 zip 信息中获得的信息作为健全性测试.这绝对不像我希望的那么简单,但组合应该让我至少 90% 确定用户的时区.

I just found a free zip database that includes time offset and participation in DST. I do like Erik J's answer, as it would help me choose the actual time zone as opposed to just the offset (because you never can be completely sure on the rules), but I think I might start with this, and have it try to find the best time zone match based on offset/dst configuration. I think I may try to set up a simple version of Development 4.0's answer to check against what I get from the zip info as a sanity test. It's definitely not as simple as I'd hope, but a combination should get me at least 90% sure of a user's time zone.

这篇关于将美国邮政编码映射到时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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