Incomplete list of timezones generated by PHP

别来无恙 提交于 2019-12-10 19:32:32

问题


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 

回答1:


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



回答2:


Tested this on my server. No problem at all. Maybe this is a server-related issue?

output: timezones.php

source-code:

<?php

foreach(DateTimeZone::listIdentifiers() as $zone) {

    echo $zone.'<br/>';

}   

?>

Best, Christian




回答3:


As Pascal MARTIN points out, the PHP time zone database is a PECL package. Since you are using a Linux host you shouldn't have any problem:

pecl install timezonedb

... or:

pecl upgrade timezonedb

Update:

I found a link with CentOS specific instructions:

  • http://www.electrictoolbox.com/correct-php-timezone/

You can also do a search:

C:\>pecl search timezonedb
Retrieving data...0%
MATCHED PACKAGES, CHANNEL PECL.PHP.NET:
=======================================
PACKAGE    STABLE/(LATEST) LOCAL
timezonedb 2011.5 (stable)       Timezone Database to be used with PHP's date and time functions



回答4:


Try calling timezone_identifiers_list(DateTimeZone::ALL_WITH_BC). That worked for me. (Found this solution from this post: https://stackoverflow.com/a/5873059/323330)



来源:https://stackoverflow.com/questions/5776392/incomplete-list-of-timezones-generated-by-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!