问题
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