在 PHP 中,如何从偏移量和国家/地区获取时区? [英] In PHP, how can I get Timezone from offset and country?

查看:50
本文介绍了在 PHP 中,如何从偏移量和国家/地区获取时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行 IP 查找,以确定时区与 UTC 和国家/地区信息的偏移量的最佳猜测".

I am doing an IP lookup to determine a "best guess" for timezone offset from UTC and the country/region information.

例如,我偏移了 -3 和国家巴西.

So, for instance, I have offset -3 and country Brazil.

我想在相同的偏移量中显示 BRT 而不是随机时区,即 ART

I want to show BRT instead of a random timezone in that same offset, i.e. ART

PHP 中是否有一些内置方法可以使用此信息设置适当的时区?

Is there some built-in way in PHP to be able to set the appropriate timezone with this information?

如果没有,最简单的方法是什么?(假设我不能进行任何外部 API 调用)

If not, what would be the easiest way to do this? (Assume that I can't make any outside API calls)

如果我做自己的数据库表,我如何确保它保持最新?

If I do my own database table, how do I ensure it stays up to date?

谢谢!

推荐答案

您不必滚动自己的数据库,这里有一个来自 地理名称.您还可以从 PHP 获取所有时区信息.

You don't have to roll your own database, here's one from GeoNames. You can also get all the timezone information from PHP.

这篇关于在 PHP 中,如何从偏移量和国家/地区获取时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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