Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Country to timezones in PHP/Zend Framework

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.

like image 234
Kevin Carrogan Avatar asked May 13 '10 11:05

Kevin Carrogan


Video Answer


1 Answers

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

  • DateTimeZone::listIdentifiers — Returns numerically index array with all timezone identifiers

Example:

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

outputs:

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
)

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).

like image 196
Gordon Avatar answered Sep 28 '22 02:09

Gordon