如何生成同时具有国家和城市名称的时区列表

我正在尝试为我的客户设置时区列表,其中包括国家名称和城市。

我正在使用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

sunnisha 回答:如何生成同时具有国家和城市名称的时区列表

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3162652.html

大家都在问