PHP/Zend 框架中的国家/地区到时区 [英] Country to timezones in PHP/Zend Framework

查看:27
本文介绍了PHP/Zend 框架中的国家/地区到时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Zend Framework 或默认 PHP 中有没有办法将国家/地区(使用国家/地区代码)映射到时区列表?例如,我在搜索澳大利亚现在的时间"时尝试复制 Google 功能,该功能显示该国家/地区的所有时区和城市.

Is there a way in Zend Framework or default PHP to map a country (using country code) to a list of timezones? As an example I'm trying to replicate the Google functionality when searching for "time in australia right now" which displays all of the timezones and cities for that country.

推荐答案

不确定 Zend_Date,但原生 PHP 从 PHP5.3 开始可以做到这一点

Not sure about Zend_Date, but native PHP can do that as of PHP5.3 with

示例:

print_r( DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'US') );

输出:

Array
(
    [0] => America/Adak
    [1] => America/Anchorage
    [2] => America/Boise
    [3] => America/Chicago
    [4] => America/Denver
    [5] => America/Detroit
    [6] => America/Indiana/Indianapolis
    [7] => America/Indiana/Knox
    [8] => America/Indiana/Marengo
    [9] => America/Indiana/Petersburg
    [10] => America/Indiana/Tell_City
    [11] => America/Indiana/Vevay
    [12] => America/Indiana/Vincennes
    [13] => America/Indiana/Winamac
    [14] => America/Juneau
    [15] => America/Kentucky/Louisville
    [16] => America/Kentucky/Monticello
    [17] => America/Los_Angeles
    [18] => America/Menominee
    [19] => America/New_York
    [20] => America/Nome
    [21] => America/North_Dakota/Center
    [22] => America/North_Dakota/New_Salem
    [23] => America/Phoenix
    [24] => America/Shiprock
    [25] => America/Yakutat
    [26] => Pacific/Honolulu
)

请注意,国家/地区必须以两个字母的 ISO 3166-1 兼容国家/地区代码形式提供.显然,这意味着我们"与美国"不同(至少当时我没有得到结果).

Note that the country must be supplied as a two-letter ISO 3166-1 compatible country code. Apparently, this means 'us' is not the same as 'US' (at least I don't get a result then).

这篇关于PHP/Zend 框架中的国家/地区到时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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