本文整理汇总了PHP中DateTimeZone::listAbbreviations方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeZone::listAbbreviations方法的具体用法?PHP DateTimeZone::listAbbreviations怎么用?PHP DateTimeZone::listAbbreviations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeZone
的用法示例。
在下文中一共展示了DateTimeZone::listAbbreviations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: timezones
function timezones()
{
$list = DateTimeZone::listAbbreviations();
$idents = DateTimeZone::listIdentifiers();
$data = array();
foreach ($list as $key => $zones) {
foreach ($zones as $id => $zone) {
if ($zone['timezone_id'] and in_array($zone['timezone_id'], $idents)) {
$offset = round(abs($zone['offset'] / 3600));
$sign = $zone['offset'] > 0 ? '+' : '-';
if ($offset == 0) {
$sign = ' ';
$offset = '';
}
$zone['label'] = 'GMT' . $sign . $offset . ' ' . $zone['timezone_id'];
$data[$zone['offset']][$zone['timezone_id']] = $zone;
}
}
}
ksort($data);
$timezones = array();
foreach ($data as $offsets) {
ksort($offsets);
foreach ($offsets as $zone) {
$timezones[] = $zone;
}
}
return $timezones;
}
示例2: getListofTimezones
private static function getListofTimezones()
{
$timezones = \DateTimeZone::listAbbreviations(\DateTimeZone::ALL);
/**
* Only get timezones explicitely not part of "Others".
* @see http://www.php.net/manual/en/timezones.others.php
*/
$cities = [];
foreach ($timezones as $key => $zones) {
foreach ($zones as $id => $zone) {
if (preg_match('/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\\//', $zone['timezone_id']) && $zone['timezone_id']) {
$cities[$zone['timezone_id']][] = $key;
}
}
}
// For each city, have a comma separated list of all possible timezones for that city.
foreach ($cities as $key => $value) {
$cities[$key] = join(', ', $value);
}
// Only keep one city (the first and also most important) for each set of possibilities.
$cities = array_unique($cities);
// Sort by area/city name.
ksort($cities);
return $cities;
}
示例3: getCachedTimeZones
/**
* @return mixed
*/
function getCachedTimeZones()
{
static $result;
if (!$result) {
$result = json_decode(json_encode(DateTimeZone::listAbbreviations()), true);
}
return $result;
}
示例4: findTimezoneByOffset
public static function findTimezoneByOffset($offset)
{
foreach (DateTimeZone::listAbbreviations() as $timezoneAbbreviations) {
foreach ($timezoneAbbreviations as $value) {
if (preg_match('/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific|Australia|UTC)/', $value['timezone_id']) && $value['offset'] == $offset) {
return $value['timezone_id'];
}
}
}
}
示例5: getTimezones
public static function getTimezones()
{
$timezones = array();
foreach (DateTimeZone::listAbbreviations() as $timezoneAbbreviations) {
foreach ($timezoneAbbreviations as $value) {
if (preg_match('/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific|Australia)\\//', $value['timezone_id'])) {
$timezones[$value['timezone_id']] = $value['offset'];
}
}
}
@ksort($timezones);
return array_keys($timezones);
}
示例6: getTimezoneStringFromGmtOffset
private static function getTimezoneStringFromGmtOffset()
{
$gmtOffset = get_option('gmt_offset') * 3600;
// convert hour offset to seconds
$timezones = DateTimeZone::listAbbreviations();
foreach ($timezones as $timezonesCities) {
foreach ($timezonesCities as $cityDetails) {
if ($cityDetails['offset'] == $gmtOffset) {
return $cityDetails['timezone_id'];
}
}
}
// no matching timezone found -- assuming UTC
return 'UTC';
}
示例7: getTimezones
/**
* retrieves an array of valid timezones for date_default_timezone_set
*
* @return array
*/
public static function getTimezones()
{
$cities = array();
foreach (DateTimeZone::listAbbreviations() as $key => $zones) {
foreach ($zones as $id => $zone) {
if (preg_match('/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\\//', $zone['timezone_id'])) {
$cities[$zone['timezone_id']][] = $key;
}
}
}
// for each city, have a comma separated list of all possible timezones for that city
foreach ($cities as $k => $v) {
$cities[$k] = implode(',', $v);
}
// only keep one city (the first and also most important) for each set of possibilities
$cities = array_unique($cities);
// sort by area/city name
ksort($cities);
return array_keys($cities);
}
示例8: checkPhpConfiguration
private function checkPhpConfiguration()
{
$category = new SettingCategory('PHP configuration');
$timezone = ini_get('date.timezone');
$category->addRequirement('Parameter date.timezone must be set in your php.ini', array(), false != $timezone);
if (version_compare(phpversion(), self::REQUIRED_PHP_VERSION, '>=')) {
$supportedTimezones = array();
foreach (\DateTimeZone::listAbbreviations() as $abbreviations) {
foreach ($abbreviations as $abbreviation) {
$supportedTimezones[] = $abbreviation['timezone_id'];
}
}
$category->addRequirement('Your default timezone (%timezone%) is not supported', array('timezone' => $timezone), in_array($timezone, $supportedTimezones));
}
$category->addRequirement('Parameter %parameter% must be set to %value% in your php.ini', array('parameter' => 'detect_unicode', 'value' => 'false'), false === ini_get('detect_unicode'));
$category->addRequirement('Parameter %parameter% should be equal or greater than %value% in your php.ini', array('parameter' => 'max_execution_time', 'value' => 60), ini_get('max_execution_time') >= 60 || ini_get('max_execution_time') == 0 ? true : false);
$category->addRecommendation('Parameter %parameter% should be equal or greater than %value% in your php.ini', array('parameter' => 'memory_limit', 'value' => '256M'), $this->isGreaterOrEqual(ini_get('memory_limit'), '256M'));
$recommendedSettings = array('short_open_tag' => false, 'magic_quotes_gpc' => false, 'register_globals' => false, 'session.auto_start' => false, 'file_uploads' => true);
foreach ($recommendedSettings as $parameter => $value) {
$category->addRecommendation('Parameter %parameter% should be set to %value% in your php.ini', array('parameter' => $parameter, 'value' => $value ? 'true' : 'false'), $value == ini_get($parameter));
}
$this->categories[] = $category;
}
示例9: getTimezoneOption
function getTimezoneOption()
{
$list = DateTimeZone::listAbbreviations();
$idents = DateTimeZone::listIdentifiers();
$data = $offset = $added = array();
foreach ($list as $abbr => $info) {
foreach ($info as $zone) {
if (!empty($zone['timezone_id']) and !in_array($zone['timezone_id'], $added) and in_array($zone['timezone_id'], $idents)) {
$z = new DateTimeZone($zone['timezone_id']);
$c = new DateTime(null, $z);
$zone['time'] = $c->format('H:i');
$data[] = $zone;
$offset[] = $z->getOffset($c);
$added[] = $zone['timezone_id'];
}
}
}
array_multisort($offset, SORT_ASC, $data);
$options = array();
foreach ($data as $key => $row) {
$options[$row['timezone_id']] = formatOffset($row['offset']) . ' ' . $row['timezone_id'];
}
return $options;
}
示例10: array
/**
* Migrate timezone abbreviations to timezone identifier
* The three letter timezone abbreviations do not play well with DST
*
* "2015-05-19 12:22:24 Europe/Tallinn"
* "2015-05-19 12:22:24 EET"
*
* should both return same date in GMT, but instead they return:
* "2015-05-19 09:22:24"
* "2015-05-19 10:22:24"
*/
// build list of abbreviation => Timezone
// we take first timezone and hope it's correct
$timezones = array();
foreach (DateTimeZone::listAbbreviations() as $abbrevation => $list) {
// take first timezone
$timezone = current($list);
$timezones[strtoupper($abbrevation)] = $timezone['timezone_id'];
}
/** @var DbInterface $db */
$res = $db->getAll('select upr_usr_id, upr_timezone from {{%user_preference}}');
foreach ($res as $row) {
$usr_id = $row['upr_usr_id'];
$tz = $row['upr_timezone'];
// skip UTC
if (in_array($tz, array('UTC', 'GMT'))) {
continue;
}
if (!$tz) {
// if empty tz, set default from system
示例11: ms2phpTZ
/**
* (very simple) conversion of a MS timezone to a PHP5 valid (Date-)timezone
* matching (MS) UCT offset and time zone descriptors
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.14.1 - 2012-09-16
* @param string $timezone, input/output variable reference
* @return bool
*/
public static function ms2phpTZ(&$timezone)
{
if (empty($timezone)) {
return FALSE;
}
$search = str_replace('"', '', $timezone);
$search = str_replace(array('GMT', 'gmt', 'utc'), 'UTC', $search);
if ('(UTC' != substr($search, 0, 4)) {
return FALSE;
}
if (FALSE === ($pos = strpos($search, ')'))) {
return FALSE;
}
$pos = strpos($search, ')');
$searchOffset = substr($search, 4, $pos - 4);
$searchOffset = iCalUtilityFunctions::_tz2offset(str_replace(':', '', $searchOffset));
while (' ' == substr($search, $pos + 1)) {
$pos += 1;
}
$searchText = trim(str_replace(array('(', ')', '&', ',', ' '), ' ', substr($search, $pos + 1)));
$searchWords = explode(' ', $searchText);
$timezone_abbreviations = DateTimeZone::listAbbreviations();
$hits = array();
foreach ($timezone_abbreviations as $name => $transitions) {
foreach ($transitions as $cnt => $transition) {
if (empty($transition['offset']) || empty($transition['timezone_id']) || $transition['offset'] != $searchOffset) {
continue;
}
$cWords = explode('/', $transition['timezone_id']);
$cPrio = $hitCnt = $rank = 0;
foreach ($cWords as $cWord) {
if (empty($cWord)) {
continue;
}
$cPrio += 1;
$sPrio = 0;
foreach ($searchWords as $sWord) {
if (empty($sWord) || 'time' == strtolower($sWord)) {
continue;
}
$sPrio += 1;
if (strtolower($cWord) == strtolower($sWord)) {
$hitCnt += 1;
$rank += $cPrio + $sPrio;
} else {
$rank += 10;
}
}
}
if (0 < $hitCnt) {
$hits[$rank][] = $transition['timezone_id'];
}
}
}
unset($timezone_abbreviations);
if (empty($hits)) {
return FALSE;
}
ksort($hits);
foreach ($hits as $rank => $tzs) {
if (!empty($tzs)) {
$timezone = reset($tzs);
return TRUE;
}
}
return FALSE;
}
示例12: content_56afda4a2140e0_61815806
//.........这里部分代码省略.........
?>
type="checkbox" class="ace ace-switch ace-switch-5">
<span class="lbl"></span>
</label>
<hr>
<label for="allow_template_change">Allow template change</label>
<label class="pull-right inline">
<input value="1" name="allow_template_change" id="allow_template_change" <?php
if ($_smarty_tpl->tpl_vars['row']->value['allow_template_change'] == 1) {
?>
checked="checked"<?php
}
?>
type="checkbox" class="ace ace-switch ace-switch-5">
<span class="lbl"></span>
</label>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label for="date_format">Date Format</label>
<input class="form-control" name="date_format" type="text" id="date_format" value="<?php
echo $_smarty_tpl->tpl_vars['row']->value['date_format'];
?>
" size="45" />
</div>
<div class="col-md-4">
<label for="default_time_zone">Default time zone</label>
<select class="form-control" name="default_time_zone" id="default_time_zone">
<?php
if (isset($_smarty_tpl->tpl_vars['timezone_abbreviations'])) {
$_smarty_tpl->tpl_vars['timezone_abbreviations'] = clone $_smarty_tpl->tpl_vars['timezone_abbreviations'];
$_smarty_tpl->tpl_vars['timezone_abbreviations']->value = DateTimeZone::listAbbreviations();
$_smarty_tpl->tpl_vars['timezone_abbreviations']->nocache = null;
$_smarty_tpl->tpl_vars['timezone_abbreviations']->scope = 0;
} else {
$_smarty_tpl->tpl_vars['timezone_abbreviations'] = new Smarty_variable(DateTimeZone::listAbbreviations(), null, 0);
}
?>
<?php
$_smarty_tpl->tpl_vars['tz'] = new Smarty_Variable();
$_smarty_tpl->tpl_vars['tz']->_loop = false;
$_from = $_smarty_tpl->tpl_vars['timezone_abbreviations']->value['est'];
if (!is_array($_from) && !is_object($_from)) {
settype($_from, 'array');
}
foreach ($_from as $_smarty_tpl->tpl_vars['tz']->key => $_smarty_tpl->tpl_vars['tz']->value) {
$_smarty_tpl->tpl_vars['tz']->_loop = true;
?>
<option value="<?php
echo $_smarty_tpl->tpl_vars['tz']->value['timezone_id'];
?>
" <?php
if ($_smarty_tpl->tpl_vars['row']->value['default_time_zone'] == $_smarty_tpl->tpl_vars['tz']->value['timezone_id']) {
?>
selected="selected"<?php
}
?>
>(GMT <?php
echo $_smarty_tpl->tpl_vars['tz']->value['offset'] / 3600;
?>
) <?php
echo $_smarty_tpl->tpl_vars['tz']->value['timezone_id'];
?>
</option>
开发者ID:reactvideos,项目名称:Website,代码行数:67,代码来源:4d803027ec049c20d27c44174279718c2d027ea0.file.main.html.php
示例13: getTimeZone
static function getTimeZone()
{
$userTz = JFactory::getUser()->getParam('timezone');
if (FSTJ3Helper::IsJ3()) {
$timeZone = JFactory::getConfig()->get('offset');
} else {
$timeZone = JFactory::getConfig()->getValue('offset');
}
if ($userTz) {
$timeZone = $userTz;
}
if ((int) $timeZone == $timeZone && is_numeric($timeZone)) {
$timeZone += FST_Settings::Get('timezone_offset');
$offset = $timeZone * 3600;
$tz = DateTimeZone::listAbbreviations();
if (count($tz) > 0) {
foreach ($tz as $zone => $things) {
if ($things[0]['offset'] == $offset) {
$timeZone = $things[0]['timezone_id'];
break;
}
}
}
}
if ((string) $timeZone == "" || (string) $timeZone == "0") {
$timeZone = "UTC";
}
return new DateTimeZone($timeZone);
}
示例14: getTZbyoffset
/**
* Get the first available timezone name
* that matches the offset value (in seconds)
*
* @param int $intOffset
* @param bool $asCommonZone
*
* @internal param number $offset of seconds from GMT
*
* @return first matching timezone name, always trying to get
* the most common name of timezone
*/
public static function getTZbyoffset($intOffset, $asCommonZone = true)
{
$tza = \DateTimeZone::listAbbreviations();
foreach ($tza as $abbr) {
foreach ($abbr as $zone) {
if ($zone['offset'] === (int) $intOffset) {
if (!$asCommonZone) {
return $zone['timezone_id'];
}
if (!isset($firstGuess)) {
$firstGuess = $zone['timezone_id'];
}
if (in_array($zone['timezone_id'], self::$commonZones)) {
return $zone['timezone_id'];
}
}
}
}
/**
* If $asCommonZone was true and no result was found
* in $commonZones map then return the first match
* else return empty string
*/
return isset($firstGuess) ? $firstGuess : '';
}
示例15: getTimezonesWithAbbreviations
/**
* Returns a list of available timezones, including timezone abbreviations.
*
* Contrary to getTimezones() the timezone IDs are values and the timezone
* labels are the keys, to allow multiple labels for the same timezone.
*
* @since 2.2.0
*
* @return array List of timezones.
*/
public static function getTimezonesWithAbbreviations()
{
$timezones = array_flip(self::getTimezones());
foreach (DateTimeZone::listAbbreviations() as $abbreviation => $timezone) {
$abbreviation = Horde_String::upper($abbreviation);
if ($abbreviation == 'UTC' || strlen($abbreviation) < 2) {
continue;
}
$timezones[$abbreviation] = $timezone[0]['timezone_id'];
}
return $timezones;
}