本文整理汇总了PHP中timezone_abbreviations_list函数的典型用法代码示例。如果您正苦于以下问题:PHP timezone_abbreviations_list函数的具体用法?PHP timezone_abbreviations_list怎么用?PHP timezone_abbreviations_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timezone_abbreviations_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse_time
function parse_time($d, $reference = null)
{
global $Now, $Opt;
if ($reference === null) {
$reference = $Now;
}
if (!isset($Opt["dateFormatTimezoneRemover"]) && function_exists("timezone_abbreviations_list")) {
$mytz = date_default_timezone_get();
$x = array();
foreach (timezone_abbreviations_list() as $tzname => $tzinfo) {
foreach ($tzinfo as $tz) {
if ($tz["timezone_id"] == $mytz) {
$x[] = preg_quote($tzname);
}
}
}
if (count($x) == 0) {
$x[] = preg_quote(date("T", $reference));
}
$Opt["dateFormatTimezoneRemover"] = "/(?:\\s|\\A)(?:" . join("|", $x) . ")(?:\\s|\\z)/i";
}
if (@$Opt["dateFormatTimezoneRemover"]) {
$d = preg_replace($Opt["dateFormatTimezoneRemover"], " ", $d);
}
$d = preg_replace('/\\butc([-+])/i', 'GMT$1', $d);
return strtotime($d, $reference);
}
示例2: get_timezone_id
public static function get_timezone_id()
{
// if site timezone string exists, return it
if ($timezone = get_option('timezone_string')) {
return $timezone;
}
// get UTC offset, if it isn't set return UTC
if (!($utc_offset = 3600 * get_option('gmt_offset', 0))) {
return 'UTC';
}
// attempt to guess the timezone string from the UTC offset
$timezone = timezone_name_from_abbr('', $utc_offset);
// last try, guess timezone string manually
if (FALSE === $timezone) {
$is_dst = date('I');
foreach (timezone_abbreviations_list() as $abbr) {
foreach ($abbr as $city) {
if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
return $city['timezone_id'];
}
}
}
}
return 'UTC';
// fallback
}
示例3: get_local_timezone
public static function get_local_timezone($reset = FALSE)
{
if ($reset) {
self::$local_timezone = NULL;
}
if (!isset(self::$local_timezone)) {
$tzstring = get_option('timezone_string');
if (empty($tzstring)) {
$gmt_offset = get_option('gmt_offset');
if ($gmt_offset == 0) {
$tzstring = 'UTC';
} else {
$gmt_offset *= HOUR_IN_SECONDS;
$tzstring = timezone_name_from_abbr('', $gmt_offset);
if (false === $tzstring) {
$is_dst = date('I');
foreach (timezone_abbreviations_list() as $abbr) {
foreach ($abbr as $city) {
if ($city['dst'] == $is_dst && $city['offset'] == $gmt_offset) {
$tzstring = $city['timezone_id'];
break 2;
}
}
}
}
if (false === $tzstring) {
$tzstring = 'UTC';
}
}
}
self::$local_timezone = new DateTimeZone($tzstring);
}
return self::$local_timezone;
}
示例4: setTimezoneByOffset
function setTimezoneByOffset($offset)
{
date_default_timezone_set('UTC');
$testTimestamp = time();
$testLocaltime = localtime($testTimestamp, true);
$testHour = $testLocaltime['tm_hour'];
$abbrarray = timezone_abbreviations_list();
foreach ($abbrarray as $abbr) {
foreach ($abbr as $city) {
$val = false;
if ($city['timezone_id'] != 'Factory' && '' . @$city['timezone_id'] > '') {
if (isset($city['timezone_id'])) {
$val = date_default_timezone_set($city['timezone_id']);
if ($val) {
$testLocaltime = localtime($testTimestamp, true);
$hour = $testLocaltime['tm_hour'];
$testOffset = $hour - $testHour;
if ($testOffset == $offset || $testOffset == $offset + 24) {
return true;
}
}
}
}
}
}
date_default_timezone_set('UTC');
return false;
}
示例5: determine_timezone_string
/**
* Returns the timezone string for a site, even if it's set to a UTC offset
*
* Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155
*
* @return string valid PHP timezone string
*/
private function determine_timezone_string()
{
// If site timezone string exists, return it.
if ($timezone = get_option('timezone_string')) {
return $timezone;
}
// Get UTC offset, if it isn't set then return UTC.
if (0 === ($utc_offset = get_option('gmt_offset', 0))) {
return 'UTC';
}
// Adjust UTC offset from hours to seconds.
$utc_offset *= HOUR_IN_SECONDS;
// Attempt to guess the timezone string from the UTC offset.
$timezone = timezone_name_from_abbr('', $utc_offset);
// Last try, guess timezone string manually.
if (false === $timezone) {
$is_dst = date('I');
foreach (timezone_abbreviations_list() as $abbr) {
foreach ($abbr as $city) {
if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
return $city['timezone_id'];
}
}
}
}
// Fallback to UTC.
return 'UTC';
}
示例6: wp_get_timezone_string
/**
* Returns the timezone string for a site, even if it's set to a UTC offset
*
* Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155
*
* @return string valid PHP timezone string
*/
private static function wp_get_timezone_string()
{
$blog_timezone = get_option('timezone_string');
$blog_gmt_offset = get_option('gmt_offset', 0);
// if site timezone string exists, return it
if ($timezone = $blog_timezone) {
return $timezone;
}
// get UTC offset, if it isn't set then return UTC
if (0 === ($utc_offset = $blog_gmt_offset)) {
return 'UTC';
}
// adjust UTC offset from hours to seconds
$utc_offset *= 3600;
// attempt to guess the timezone string from the UTC offset
if ($timezone = timezone_name_from_abbr('', $utc_offset, 0)) {
return $timezone;
}
// last try, guess timezone string manually
$is_dst = date('I');
foreach (timezone_abbreviations_list() as $abbr) {
foreach ($abbr as $city) {
if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
return $city['timezone_id'];
}
}
}
// fallback to UTC
return 'UTC';
}
示例7: validTimezone
public function validTimezone($timezone)
{
$validTimezones = array();
$availableTimezones = timezone_abbreviations_list();
foreach ($availableTimezones as $zone) {
foreach ($zone as $item) {
$validTimezones[$item['timezone_id']] = true;
}
}
unset($validTimezones['']);
return isset($validTimezones[$timezone]);
}
示例8: getTimezoneByOffset
function getTimezoneByOffset($offset)
{
$offset *= 3600;
// convert hour offset to seconds
$abbrarray = timezone_abbreviations_list();
foreach ($abbrarray as $abbr) {
foreach ($abbr as $city) {
if ($city['offset'] == $offset) {
return $city['timezone_id'];
}
}
}
return false;
}
示例9: get_timezones
/**
* Returns possible timezones as:
* array(
* '<timezone name>' => <true for DST, false otherwise>,
* ...
* )
*
* @return array
*/
function get_timezones()
{
$timezones = array();
foreach (timezone_abbreviations_list() as $tz_abbreviation) {
foreach ($tz_abbreviation as $timezone) {
if (strlen($timezone['timezone_id']) === 0) {
continue;
}
$timezones[$timezone['timezone_id']] = $timezone['dst'];
}
}
ksort($timezones);
return $timezones;
}
示例10: tzOffsetToName
/**
* Timezone name
*
* @param sting $offset
*
* @return timezone name
*/
public static function tzOffsetToName($offset)
{
$offset *= 3600;
// convert hour offset to seconds
$abbrarray = timezone_abbreviations_list();
foreach ($abbrarray as $abbr) {
foreach ($abbr as $city) {
if ($city['offset'] == $offset) {
return $city['timezone_id'];
}
}
}
return FALSE;
}
示例11: _timezone_convert_to_string_from_offset
/**
* all this method does is take an incoming GMT offset value ( e.g. "+1" or "-4" ) and returns a corresponding valid DateTimeZone() timezone_string.
* @param string $offset GMT offset
* @return string timezone_string (valid for DateTimeZone)
*/
private static function _timezone_convert_to_string_from_offset($offset)
{
//shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did NOT work as expected - its not reliable
$offset *= 3600;
// convert hour offset to seconds
$abbrarray = timezone_abbreviations_list();
foreach ($abbrarray as $abbr) {
foreach ($abbr as $city) {
if ($city['offset'] === $offset && $city['dst'] === FALSE) {
return $city['timezone_id'];
}
}
}
return FALSE;
}
示例12: set_tz_by_offset
public function set_tz_by_offset($offset)
{
$offset = $offset * 60 * 60;
$abbrarray = timezone_abbreviations_list();
foreach ($abbrarray as $abbr) {
foreach ($abbr as $city) {
if ($city['offset'] == $offset) {
// remember to multiply $offset by -1 if you're getting it from js
date_default_timezone_set($city['timezone_id']);
return true;
}
}
}
date_default_timezone_set("ust");
return false;
}
示例13: set_time_zone
function set_time_zone($time_zone)
{
if (preg_match('/(\\+|-)([0-9]{2}):([0-9]{2})/', $time_zone, $matches)) {
list(, $sign, $hours, $minutes) = $matches;
$offset = ($sign == '+' ? 1 : -1) * ((int) $hours * 3600 + (int) $minutes * 60);
if (($time_zone = timezone_name_from_abbr('', $offset, 0)) === FALSE) {
foreach (timezone_abbreviations_list() as $abbr) {
foreach ($abbr as $zone) {
if (!$zone['dst'] && $zone['offset'] == $offset) {
return date_default_timezone_set($zone['timezone_id']);
}
}
}
}
}
return $time_zone ? date_default_timezone_set($time_zone) : FALSE;
}
示例14: TSfromLocalTS
function TSfromLocalTS($ts)
{
$ts = (int) $ts;
$uid = (int) sUserMgr()->getCurrentUserID();
$user = new User($uid);
$user_timezone = $user->properties->getValue('TIMEZONE');
$tz = null;
$offset = null;
$timezoneAbbreviations = timezone_abbreviations_list();
foreach ($timezoneAbbreviations as $timezoneAbbreviations_item) {
foreach ($timezoneAbbreviations_item as $timezone_item) {
if ($timezone_item['timezone_id'] == $user_timezone) {
$tz = $timezone_item;
$offset = $timezone_item['offset'];
}
}
}
//Windows special fallback
if (!$tz) {
switch ($user_timezone) {
case 'Etc/GMT-11':
$offset = -39600;
break;
case 'Etc/GMT-2':
$offset = -7200;
break;
case 'Atlantic/South_Georgia':
$offset = -7200;
break;
case 'GMT':
$offset = 0;
break;
case 'Etc/GMT+12':
$offset = 43200;
break;
}
}
// Save original timezone
$currentTimeZone = date_default_timezone_get();
// Get offset of user timezone
date_default_timezone_set($user_timezone);
$realOffset = date('Z', $ts);
// Reset original timezone
date_default_timezone_set($currentTimeZone);
return $ts - $realOffset;
}
示例15: getTz_array
public static function getTz_array()
{
$tz_array = array();
foreach (timezone_abbreviations_list() as $abbr => $array) {
foreach ($array as $id => $array2) {
$offset = $array2['offset'];
$timezone_id = $array2['timezone_id'];
//$tz_byTimeZone[$timezone_id] = format_time($offset);
//$tz_byOffset[format_time($offset)] = $timezone_id;
$tz_array[$timezone_id] = array('timezone_id' => $timezone_id, 'offset' => TimezoneController::format_time($offset), 'int_offset' => round($offset / 60, 0));
}
//exit;
}
usort($tz_array, function ($a, $b) {
return $a['offset'] - $b['offset'];
});
return $tz_array;
}