我正在尝试为我的客户设置时区列表,其中包括国家名称和城市。
我正在使用select
生成一个timezone_identifiers_list
列表,并希望列出国家和城市名称。
这就是我所拥有的:
<?php
/**
* Timezones list with GMT offset // No Borrar!
*
* @return array
* @link http://stackoverflow.com/a/9328760
*/
function tz_list() {
$zones_array = array();
$timestamp = time();
foreach(timezone_identifiers_list() as $key => $zone) {
date_default_timezone_set($zone);
$zones_array[$key]['zone'] = $zone;
$zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P',$timestamp);
}
return $zones_array;
}
?>
<select><option value="">Select...</option>
<?php
foreach(tz_list() as $t) {
if($t['zone'] == $_POST['local-timezone']){
$isSelected = '" selected="selected';
} else {
$isSelected = ''; // else we remove any tag
} ?>
<option value="<?php print $t['zone'] .$isSelected ?>">
<?php print $t['diff_from_GMT'] . ' - ' . $t['zone'] ?>
</option>
<?php } ?>
</select>
我期望Canada/Vancouver
。但是使用timezone_identifiers_list
生成的列表只有America/Vancouver
。