Search code examples
phptimezoneregion

Incomplete list of timezones generated by PHP


I've tried generating the complete set of timezones as specified in http://php.net/manual/en/timezones.php (except UTC) by using the following code:

$zones = timezone_identifiers_list();

print_r($zones);

But this list seems to skip ~ 50 regions, eg: Pacific/Samoa (as compared to http://php.net/manual/en/timezones.php)

What are we doing wrong?

phpinfo() shows:

PHP Version 5.3.4
Apache Version  Apache/2.2.3 (CentOS) 

$ uname -r
2.6.18-028stab070.14

Edit #2

date
date/time support   enabled
"Olson" Timezone Database Version   0.system
Timezone Database   internal
Default timezone    UTC 

Solution

  • Your timezone database might not be up-to-date.

    Try following the link at the bottom of the List of Supported Timezones page :

    The latest version of the timezone database can be installed via PECL's » timezonedb.



    Edit after the comments : to update your timezone database, as you are on a Linux system, you can use the pecl command (I just tried this on my Ubuntu machine) :

    pecl upgrade timezonedb
    

    This will download the new version, and compile it.

    Then, if you enable the new timezonedb extension, your PHP should use an uptodate database :

    php -dextension=timezonedb.so -i | grep Timezone
    "Olson" Timezone Database Version => 2011.5
    Timezone Database => external
    Alternative Timezone Database => enabled
    Timezone Database Version => 2011.5
    

    If I try without enabling that new extension, I get the same kind of thing you had before :

    php -i | grep Timezone
    "Olson" Timezone Database Version => 0.system
    Timezone Database => internal