当前位置: 首页>>代码示例>>PHP>>正文


PHP DateTimeZone::getLocation方法代码示例

本文整理汇总了PHP中DateTimeZone::getLocation方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeZone::getLocation方法的具体用法?PHP DateTimeZone::getLocation怎么用?PHP DateTimeZone::getLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTimeZone的用法示例。


在下文中一共展示了DateTimeZone::getLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_nearest_timezone

 public static function get_nearest_timezone($cur_lat, $cur_long, $country_code = '')
 {
     $timezone_ids = $country_code ? DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country_code) : DateTimeZone::listIdentifiers();
     if ($timezone_ids && is_array($timezone_ids) && isset($timezone_ids[0])) {
         $time_zone = '';
         $tz_distance = 0;
         //only one identifier?
         if (count($timezone_ids) == 1) {
             $time_zone = $timezone_ids[0];
         } else {
             foreach ($timezone_ids as $timezone_id) {
                 $timezone = new DateTimeZone($timezone_id);
                 $location = $timezone->getLocation();
                 $tz_lat = $location['latitude'];
                 $tz_long = $location['longitude'];
                 $theta = $cur_long - $tz_long;
                 $distance = sin(deg2rad($cur_lat)) * sin(deg2rad($tz_lat)) + cos(deg2rad($cur_lat)) * cos(deg2rad($tz_lat)) * cos(deg2rad($theta));
                 $distance = acos($distance);
                 $distance = abs(rad2deg($distance));
                 // echo '<br />'.$timezone_id.' '.$distance;
                 if (!$time_zone || $tz_distance > $distance) {
                     $time_zone = $timezone_id;
                     $tz_distance = $distance;
                 }
             }
         }
         return $time_zone;
     }
     return 'unknown';
 }
开发者ID:nitinprajapati1404,项目名称:YiiGeneralAdmin,代码行数:30,代码来源:TimeZone.php

示例2: tzdata

 /**
 		Return additional information for specified Unix timezone
 			@return array
 			@param $id string
 			@private
 	**/
 private static function tzdata($id)
 {
     $ref = new DateTimeZone($id);
     $loc = $ref->getLocation();
     $now = time();
     $trn = $ref->getTransitions($now, $now);
     return array('offset' => $ref->getOffset(new DateTime('now', new DateTimeZone('GMT'))) / 3600, 'country' => $loc['country_code'], 'latitude' => $loc['latitude'], 'longitude' => $loc['longitude'], 'dst' => $trn[0]['isdst']);
 }
开发者ID:huckfinnaafb,项目名称:leviatha,代码行数:14,代码来源:geo.php

示例3: tzinfo

 /**
  *	Return information about specified Unix time zone
  *	@return array
  *	@param $zone string
  **/
 function tzinfo($zone)
 {
     $ref = new \DateTimeZone($zone);
     $loc = $ref->getLocation();
     $trn = $ref->getTransitions($now = time(), $now);
     $out = array('offset' => $ref->getOffset(new \DateTime('now', new \DateTimeZone('GMT'))) / 3600, 'country' => $loc['country_code'], 'latitude' => $loc['latitude'], 'longitude' => $loc['longitude'], 'dst' => $trn[0]['isdst']);
     unset($ref);
     return $out;
 }
开发者ID:mm999,项目名称:selfoss,代码行数:14,代码来源:geo.php

示例4: timezoneByCoordinates

 /**
  * Gets the timezone that is closest to the given coordinates
  *
  * @param float $lag
  * @param float $lng
  * @return DateTimeZone Timezone object
  */
 public static function timezoneByCoordinates($lat, $lng)
 {
     $current = ['timezone' => null, 'distance' => 0];
     $identifiers = DateTimeZone::listIdentifiers();
     foreach ($identifiers as $identifier) {
         $timezone = new DateTimeZone($identifier);
         $location = $timezone->getLocation();
         $point = ['lat' => $location['latitude'], 'lng' => $location['longitude']];
         $distance = (int) GeocodeLib::calculateDistance(compact('lat', 'lng'), $point);
         if (!$current['distance'] || $distance < $current['distance']) {
             $current = ['timezone' => $identifier, 'distance' => $distance];
         }
     }
     return $current['timezone'];
 }
开发者ID:ByMyHandsOnly,项目名称:BMHO_Web,代码行数:22,代码来源:TimeLib.php

示例5: timezone

 public static function timezone($latitude, $longitude)
 {
     $alltimezones = DateTimeZone::listIdentifiers();
     $variances = array();
     //calculate for all timezones the system know
     foreach ($alltimezones as $timezone) {
         $datetimezoneobj = new DateTimeZone($timezone);
         $locationinformations = $datetimezoneobj->getLocation();
         $latitudeoftimezone = $locationinformations['latitude'];
         $longitudeoftimezone = $locationinformations['longitude'];
         $variances[abs($latitudeoftimezone - $latitude) + abs($longitudeoftimezone - $longitude)] = $timezone;
     }
     //sort array and return the timezone with the smallest difference
     ksort($variances);
     reset($variances);
     return current($variances);
 }
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:17,代码来源:geo.php

示例6: getClosestTimezone

/**
 * Attempts to find the closest timezone by coordinates
 *
 * @static
 * @param $lat
 * @param $lng
 */
function getClosestTimezone($lat, $lng)
{
    $diffs = array();
    foreach (DateTimeZone::listIdentifiers() as $timezoneID) {
        $timezone = new DateTimeZone($timezoneID);
        $location = $timezone->getLocation();
        $tLat = $location['latitude'];
        $tLng = $location['longitude'];
        $diffLat = abs($lat - $tLat);
        $diffLng = abs($lng - $tLng);
        $diff = $diffLat + $diffLng;
        $diffs[$timezoneID] = $diff;
    }
    //asort($diffs);
    $timezone = array_keys($diffs, min($diffs));
    return $timezone[0];
}
开发者ID:U0400004,项目名称:dew1,代码行数:24,代码来源:timezoneget.php

示例7: calculate_sun_rise_set

function calculate_sun_rise_set()
{
    $tzone = date_default_timezone_get();
    if ($tzone == '') {
        $tzone = 'Europe/Berlin';
    }
    $tz = new DateTimeZone($tzone);
    $loc = $tz->getLocation();
    $sun_info = date_sun_info(time(), $loc['latitude'], $loc['longitude']);
    //returns sunrise, sunset, ...
    //echo "Sunrise: " . date("H:i:s", $sun_info['sunrise']) . "\n";
    //echo "Sunset: " . date("H:i:s", $sun_info['sunset']) . "\n";
    //update sunrise
    $sql = query("SELECT id,suninfo,name FROM timer WHERE suninfo='sunset' OR suninfo='sunrise'");
    while ($row = fetch($sql)) {
        //echo $row['suninfo'] . $row['name'] ;
        if ($row['suninfo'] == 'sunrise') {
            $sqlset = query("UPDATE timer SET time = '" . date("H:i", $sun_info['sunrise']) . "', hour ='" . date("H", $sun_info['sunrise']) . "', minute ='" . date("i", $sun_info['sunrise']) . "' WHERE id = '" . $row['id'] . "'");
        }
        if ($row['suninfo'] == 'sunset') {
            $sqlset = query("UPDATE timer SET time = '" . date("H:i", $sun_info['sunset']) . "', hour ='" . date("H", $sun_info['sunset']) . "', minute ='" . date("i", $sun_info['sunset']) . "' WHERE id = '" . $row['id'] . "'");
        }
    }
}
开发者ID:mp84,项目名称:pool,代码行数:24,代码来源:cronjop.php

示例8: findTimezone

 /**
  *
  * @return string $timezone
  */
 public static function findTimezone()
 {
     $locale = self::getLocale();
     if (!$locale->getRegion()) {
         try {
             $locale = new Zend_Locale($locale . '_' . strtoupper($locale));
         } catch (Exception $e) {
         }
     }
     $region = $locale->getRegion();
     if ($region) {
         $timezoneList = Zend_Locale::getTranslationList('TimezoneToTerritory');
         if (isset($timezoneList[$region])) {
             $timezone = $timezoneList[$region];
             return $timezone;
         }
     }
     $httpCookieObject = new Zend_Http_Cookie('timezone', null, Zmz_Host::getHostname());
     $cookie = new Zmz_Cookie($httpCookieObject);
     $timezoneCookieValue = $cookie->getValue();
     $timezoneArray = @explode('/', $timezoneCookieValue);
     // check valid cookie
     if (isset($timezoneArray[0]) && isset($timezoneArray[1])) {
         $offset = intval($timezoneArray[0]);
         $dts = intval($timezoneArray[1]);
         $guessedTimezone = timezone_name_from_abbr('', $offset, $dts);
         try {
             $tz = new DateTimeZone($guessedTimezone);
             $guessedLocation = $tz->getLocation();
             //                $guessedLocationCode = $guessedLocation['country_code'];
             $timezone = $guessedTimezone;
         } catch (Exception $e) {
             $timezone = self::$defaultTimezone;
         }
     } else {
         $timezone = self::$defaultTimezone;
     }
     return $timezone;
 }
开发者ID:massimozappino,项目名称:zmz,代码行数:43,代码来源:Culture.php

示例9: mktime

echo "<br/>";
$winter = new DateTime('2010-12-21', new DateTimeZone('America/New_York'));
$summer = new DateTime('2008-06-21', new DateTimeZone('America/New_York'));
echo $winter->getOffset() . "\n";
echo $summer->getOffset() . "\n";
echo "<br/>";
$date = new DateTime();
echo $date->getTimestamp();
echo "<br/>";
$date = new DateTime(null, new DateTimeZone('Europe/London'));
$tz = $date->getTimezone();
echo $tz->getName();
echo "<br/>";
echo "<pre>";
$tz = new DateTimeZone("Europe/Prague");
print_r($tz->getLocation());
print_r(timezone_location_get($tz));
//checkdate用于验证一个验证一个格里高里日期(就是公历)
var_dump(checkdate(12, 31, 2000));
var_dump(checkdate(2, 29, 2001));
echo "<br/>";
echo "<pre>";
print_r(date_parse("2006-12-12 10:00:00.5"));
echo "<br/>";
echo "<pre>";
$today = getdate();
print_r($today);
//返回Uinx时间戳
echo "<br/>";
//hour,minute,second,month,day,year
echo mktime(0, 0, 0, 1, 1, 2000);
开发者ID:ShuiMuQinHua,项目名称:php_everyday,代码行数:31,代码来源:calendar.php

示例10: DateTimeZone

<?php

$timezone = new DateTimeZone('Europe/Rome');
echo $timezone->getName();
print_r($timezone->getLocation());
?>

开发者ID:GrUSP,项目名称:php_best_practices,代码行数:6,代码来源:02.1.php-timezone.php

示例11: _client_event

 /**
  * Convert an event object to be used on the client
  */
 private function _client_event($event, $addcss = false)
 {
     $cal_tz = $this->timezone->getName();
     if (!$event['allday'] && $event['tzname'] && $cal_tz != $event['tzname']) {
         $cal_tz = new DateTimeZone($cal_tz);
         $event_tz = new DateTimeZone($event['tzname']);
         $event['tzinfo'] = $event_tz->getLocation();
         $cal_dt = new DateTime(date('Y-m-d H:i:s', $event['start']->format('U')), $cal_tz);
         $event_dt = new DateTime(date('Y-m-d H:i:s', $event['start']->format('U')), $event_tz);
         $event['tzadjust'] = -($cal_dt->getOffset() - $event_dt->getOffset());
     } else {
         $event['tzadjust'] = 0;
     }
     // compose a human readable strings for alarms_text and recurrence_text
     if ($event['alarms']) {
         $event['alarms_text'] = libcalendaring::alarms_text($event['alarms']);
     }
     if ($event['recurrence']) {
         $event['recurrence_text'] = $this->_recurrence_text($event['recurrence']);
         if ($event['recurrence']['UNTIL']) {
             $event['recurrence']['UNTIL'] = $this->lib->adjust_timezone($event['recurrence']['UNTIL'], $event['allday'])->format('c');
         }
         unset($event['recurrence']['EXCEPTIONS']);
         // format RDATE values
         if (is_array($event['recurrence']['RDATE'])) {
             $libcal = $this->lib;
             $event['recurrence']['RDATE'] = array_map(function ($rdate) use($libcal) {
                 return $libcal->adjust_timezone($rdate, true)->format('c');
             }, $event['recurrence']['RDATE']);
         }
     }
     foreach ((array) $event['attachments'] as $k => $attachment) {
         $event['attachments'][$k]['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']);
     }
     // check for organizer in attendees list
     $organizer = null;
     foreach ((array) $event['attendees'] as $i => $attendee) {
         if (isset($attendee['role']) && $attendee['role'] == 'ORGANIZER') {
             $organizer = $attendee;
             break;
         }
     }
     if ($organizer === null && !empty($event['organizer'])) {
         $organizer = $event['organizer'];
         $organizer['role'] = 'ORGANIZER';
         if (!is_array($event['attendees'])) {
             $event['attendees'] = array();
         }
         array_unshift($event['attendees'], $organizer);
     }
     // mapping url => vurl because of the fullcalendar client script
     $event['vurl'] = $event['url'];
     unset($event['url']);
     // Begin mod by Rosali (https://issues.kolab.org/show_bug.cgi?id=3481)
     // Fix 1 second issue of all-day events
     if ($event['allday'] && isset($event['end'])) {
         if ($event['start'] == $event['end']) {
             $event['end']->modify('+ 1 day');
             $event['end']->modify('- 1 minute');
         }
     }
     $start = $event['start'] ? $event['start']->format('c') : null;
     $end = $event['end'] ? $event['end']->format('c') : null;
     if (!$event['allday']) {
         if (isset($event['end'])) {
             $estart = $event['start']->format('U');
             $eend = $event['end']->format('U');
             if ($eend - $estart > $this->rc->config->get('calendar_treat_as_allday', 6) * 3600) {
                 $view_start = get_input_value('start', RCUBE_INPUT_GPC);
                 $view_end = get_input_value('end', RCUBE_INPUT_GPC);
                 $event['allday'] = true;
                 $event['allDayfake'] = true;
                 if ($event['start']->format('U') >= $view_start) {
                     $event['left'] = $event['start']->format($this->rc->config->get('time_format', 'H:i'));
                 } else {
                     $event['left'] = '';
                 }
                 if ($event['end']->format('U') <= $view_end) {
                     $event['right'] = $event['end']->format($this->rc->config->get('time_format', 'H:i'));
                 } else {
                     $event['right'] = '';
                 }
             }
         }
     }
     $tempClass = $event['temp'] ? 'fc-event-temp ' : '';
     // End mod by Rosali
     // Begin mod by Rosali (advanced categories colorizing)
     if (is_string($event['categories'])) {
         $event['categories'] = explode(',', $event['categories']);
         foreach ($event['categories'] as $idx => $cat) {
             $event['categories'][$idx] = trim($cat);
         }
     }
     $readwrite_color = $this->rc->config->get('calendar_events_default_background_color', $this->defaults['calendar_events_default_background_color']);
     $readonly_color = $this->rc->config->get('calendar_readonly_events_default_background_color', $this->defaults['calendar_event_defaults_background_color']);
     $mode = $this->rc->config->get('calendar_event_coloring', $this->defaults['calendar_event_coloring']);
//.........这里部分代码省略.........
开发者ID:MetallianFR68,项目名称:myroundcube,代码行数:101,代码来源:calendar.php

示例12: count

<?php

$identifiers = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'IR');
echo '<p>' . count($identifiers) . ' identifiers found:</p>';
echo '<ul>';
foreach ($identifiers as $id) {
    echo '<li>';
    echo $id;
    $tz = new DateTimeZone($id);
    $comments = $tz->getLocation()['comments'];
    if ($comments) {
        echo ' : ' . $comments;
    }
    echo '</li>';
}
echo '</ul>';
开发者ID:hassanazimi,项目名称:PHP_DateTime,代码行数:16,代码来源:identifiers.php

示例13: getLatLng

 /**
  * This function returns an array with the most likely latitude and longitud.
  * We can get the Lat and Lng from Php's TimeZone object. We can also get it
  * from the ipSearch function here which would be more accurate.
  */
 public function getLatLng()
 {
     // do we have an api key for the IP?
     if (Phpfox::getParam('core.ip_infodb_api_key') != '') {
         $aInfo = $this->ipSearch(Phpfox_Request::instance()->getServer('REMOTE_ADDR'));
         // $this->ipSearch($_SERVER['REMOTE_ADDR']);
         if (isset($aInfo[Phpfox::getPhrase('admincp.longitude')]) && !empty($aInfo[Phpfox::getPhrase('admincp.longitude')]) && isset($aInfo[Phpfox::getPhrase('admincp.latitude')]) && !empty($aInfo[Phpfox::getPhrase('admincp.latitude')])) {
             return array('latitude' => $aInfo[Phpfox::getPhrase('admincp.latitude')], 'longitude' => $aInfo[Phpfox::getPhrase('admincp.longitude')]);
         }
     }
     // has user set a country
     if (($sTz = Phpfox::getUserBy('time_zone')) != '' && PHPFOX_USE_DATE_TIME) {
         $aTZ = $this->getTimeZones();
         if (isset($aTZ[$sTz])) {
             $oTz = new DateTimeZone($aTZ[$sTz]);
             $aInfo = $oTz->getLocation();
             return array('latitude' => $aInfo['latitude'], 'longitude' => $aInfo['longitude']);
         }
     }
     /* return a default value (London GMT0)*/
     return array('latitude' => '51.544627', 'longitude' => '-0.184021');
 }
开发者ID:Goudarzi-hahram,项目名称:phpfox,代码行数:27,代码来源:core.class.php

示例14: getGeolocationFromTimezone

 /**
  * Get location information for a timezone, including country_code, latitude, longitude and comments.
  * @param string $timezoneIdentifier
  * @return array
  */
 public static function getGeolocationFromTimezone($timezoneIdentifier)
 {
     $tz = new DateTimeZone($timezoneIdentifier);
     return $tz->getLocation();
 }
开发者ID:mindaugas-valinskis,项目名称:doophp,代码行数:10,代码来源:DooTimezone.php

示例15: DateTimeZone

<?php

$timeZone = ini_get('date.timezone');
$dtz = new DateTimeZone($timeZone);
echo "Server's Time Zone: " . $timeZone . "<br/>";
foreach ($dtz->getLocation() as $key => $value) {
    echo $key . " " . $value . "<br/>";
}
开发者ID:JohnWSteill,项目名称:EdProjs,代码行数:8,代码来源:17_2.php


注:本文中的DateTimeZone::getLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。