本文整理汇总了PHP中DateTimeObj::getTimezones方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeObj::getTimezones方法的具体用法?PHP DateTimeObj::getTimezones怎么用?PHP DateTimeObj::getTimezones使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeObj
的用法示例。
在下文中一共展示了DateTimeObj::getTimezones方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildTZSelection
/**
* Builds a XMLElement containing a `<select>` with all the available timezone
* options grouped by the different DateTimeZone constants allowed by an instance
* of this field. Developers can select what Timezones are available from the
* Section Editor.
*
* @link http://www.php.net/manual/en/class.datetimezone.php
* @param array $data
* @param string $prefix
* @param string $postfix
* @return XMLElement
*/
public function buildTZSelection($data = array(), $prefix = null, $postfix = null)
{
if (is_null($data)) {
$data = array();
}
$groups = array();
if ($this->get('required') != 'yes') {
$groups[] = array(NULL, false, NULL);
}
$zones = explode(",", $this->get('available_zones'));
foreach ($zones as $zone) {
$timezones = DateTimeObj::getTimezones($zone);
$options = array();
foreach ($timezones as $timezone) {
$tz = new DateTime('now', new DateTimeZone($timezone));
$options[] = array($timezone, $timezone == $data['value'], sprintf("%s %s", str_replace('_', ' ', substr(strrchr($timezone, '/'), 1)), $tz->format('P')));
}
$groups[] = array('label' => ucwords(strtolower($zone)), 'options' => $options);
}
$label = new XMLElement('label', $this->get('label'));
$label->appendChild(Widget::Select("fields{$prefix}[{$this->get('element_name')}]{$postfix}", $groups));
return $label;
}