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


PHP DateTimeZone::getOffset方法代码示例

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


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

示例1: testConstruct

 public function testConstruct()
 {
     $calendar = new Calendar('America/Regina');
     $tz = new \DateTimeZone($calendar->getTimezoneId());
     $dt = new \DateTime('now', $tz);
     $this->assertEquals(date_default_timezone_get(), $calendar->getTimezoneId());
     $this->assertEquals($dt->format('T'), $calendar->getTimezoneName());
     $this->assertEquals($tz->getOffset(new \DateTime()), $calendar->getTimezoneOffsetStart());
     $this->assertEquals($tz->getOffset(new \DateTime()), $calendar->getTimezoneOffsetEnd());
 }
开发者ID:tentwofour,项目名称:ical,代码行数:10,代码来源:CalendarTest.php

示例2: __construct

 /**
  * @param null $timezoneId
  */
 public function __construct($timezoneId = null)
 {
     $tz = null === $timezoneId ? date_default_timezone_get() : $timezoneId;
     $this->setTimezoneId($tz);
     // Create a new \DateTime in the default timezone
     $t = new \DateTimeZone($this->getTimezoneId());
     $d = new \DateTime('now', $t);
     $polarity = $t->getOffset($d) / 3600 === 0 ? '' : $t->getOffset($d) / 3600 < 0 ? '-' : '+';
     $this->setTimezoneName($d->format('T'));
     $this->setTimezoneOffsetStart($polarity . gmdate('hi', $t->getOffset($d)));
     $this->setTimezoneOffsetEnd($polarity . gmdate('hi', $t->getOffset($d)));
     $this->events = new ArrayCollection();
     return $this;
 }
开发者ID:tentwofour,项目名称:ical,代码行数:17,代码来源:Calendar.php

示例3: offset

 /**
  * Returns the offset (in seconds) between two time zones.
  * @see     http://php.net/timezones
  *
  * @param   string          timezone that to find the offset of
  * @param   string|boolean  timezone used as the baseline
  * @return  integer
  */
 public static function offset($remote, $local = YES, $alt_format = false)
 {
     static $offsets;
     // Default values
     $remote = (string) $remote;
     $local = $local === YES ? date_default_timezone_get() : (string) $local;
     // Cache key name
     $cache = $remote . $local;
     if (empty($offsets[$cache])) {
         // Create timezone objects
         $remote = new DateTimeZone($remote);
         $local = new DateTimeZone($local);
         // Create date objects from timezones
         $time_there = new DateTime('now', $remote);
         $time_here = new DateTime('now', $local);
         // Find the offset
         $offset = $remote->getOffset($time_there) - $local->getOffset($time_here);
         // Return offset in +3:00 format
         if ($alt_format) {
             $offset = $offset / 60;
             $hours = floor($offset / 60);
             $min = str_pad(abs($offset % 60), 2, 0);
             if ($hours > 0) {
                 $hours = '+' . $hours;
             }
             $offsets[$cache] = $hours . ':' . $min;
         } else {
             $offsets[$cache] = $offset;
         }
     }
     return $offsets[$cache];
 }
开发者ID:shnhrrsn-abandoned,项目名称:EightPHP,代码行数:40,代码来源:date.php

示例4: testUsingYiiTimeZoneSwitcherWithPhpTimeFunction

 public function testUsingYiiTimeZoneSwitcherWithPhpTimeFunction()
 {
     $oldTimeZone = Yii::app()->getTimeZone();
     $dateTimeUtc = new DateTime();
     $timeStamp = time();
     //always UTC regardless of server timezone or any timezone setting.
     Yii::app()->setTimeZone('UTC');
     $dateStamp = date("Y-m-d G:i", $timeStamp);
     Yii::app()->setTimeZone('America/Chicago');
     $dateStamp2 = date("Y-m-d G:i", $timeStamp);
     Yii::app()->setTimeZone('America/New_York');
     $timeZoneObject = new DateTimeZone('America/New_York');
     $offset = $timeZoneObject->getOffset(new DateTime());
     $this->assertTrue($offset == -18000 || $offset == -14400);
     $newYorkTimeZone = new DateTimeZone(date_default_timezone_get());
     $offset1 = $newYorkTimeZone->getOffset($dateTimeUtc);
     $offset2 = timezone_offset_get($newYorkTimeZone, $dateTimeUtc);
     $this->assertEquals($offset, $offset1);
     $this->assertEquals($offset, $offset2);
     if ($offset == -18000) {
         $offsetHours = 6;
     } else {
         $offsetHours = 5;
     }
     $dateStamp3 = date("Y-m-d G:i", $timeStamp);
     $this->assertEquals(strtotime($dateStamp), strtotime($dateStamp2) + 3600 * $offsetHours);
     // + 5 from GMT or +6 depending on DST
     $this->assertEquals(strtotime($dateStamp3), strtotime($dateStamp2) + 3600 * 1);
     // + 1 from NY
     //Use retrieved offset based on timezone.
     Yii::app()->setTimeZone($oldTimeZone);
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:32,代码来源:TimeZoneTest.php

示例5: getOffset

 /**
  * Get the offset time between from timezone and to timezone.
  * @param        string $from_timezone Timezone departure
  * @param        string $to_timezone   Timezone arrival
  * @return       seconds                Timezone offset
  */
 public static function getOffset($from_timezone = "", $to_timezone = "")
 {
     if ($from_timezone === "" || $to_timezone === "") {
         return 0;
     }
     try {
         // Create two timezone objects, one for Singapore (Taiwan) and one for
         // Tokyo (Jakarta)
         $dateTimeFromZone = new \DateTimeZone($from_timezone);
         $dateTimeToZone = new \DateTimeZone($to_timezone);
         $date = (new \DateTime())->format('Y-m-d H:i:s');
         $datTimeFrom = new \DateTime($date, $dateTimeFromZone);
         $dateTimeTo = new \DateTime($date, $dateTimeToZone);
         // Calculate the GMT offset for the date/time contained in the $datTimeFrom
         // object, but using the timezone rules as defined for Tokyo
         // ($dateTimeToZone).
         $timeOffset = $dateTimeToZone->getOffset($datTimeFrom);
         $timeOffset2 = $dateTimeFromZone->getOffset($dateTimeTo);
         // Should show int(32400) (for dates after Sat Sep 8 01:00:00 1951 JST).
         $offset = $timeOffset - $timeOffset2;
         return $offset;
     } catch (\Exception $e) {
         return 0;
     }
 }
开发者ID:adkarta,项目名称:datehelper,代码行数:31,代码来源:Timezone.php

示例6: timezones_from_countryCode

function timezones_from_countryCode($country_code, $country_name)
{
    $dt = new DateTime();
    // create a list of timezones based on that country code..
    $timezones = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country_code);
    $timezone_offset = [];
    // instantiate timezone_offset array
    foreach ($timezones as $timezone) {
        $tz = new DateTimeZone($timezone);
        $timezone_offset[$timezone] = $tz->getOffset(new DateTime());
    }
    // sort by offset
    asort($timezone_offset);
    // format display of timezone and offset
    foreach ($timezone_offset as $raw_timezone => $offset) {
        $dt->setTimezone(new DateTimeZone($raw_timezone));
        $timezone_abbr = $dt->format('T');
        $offset_prefix = $offset < 0 ? '-' : '+';
        $offset_formatted = gmdate('H:i', abs($offset));
        $pretty_offset = "UTC{$offset_prefix}{$offset_formatted}";
        // if( ($pos = strpos($raw_timezone, '/') ) !== false ) { // remove 'America/'
        // 	$clean_timezone = substr($raw_timezone, $pos+1);
        // 	if( ($pos = strpos($clean_timezone, '/')) !== false ) { // remove second level '.../'
        // 		$clean_timezone = substr($clean_timezone, $pos+1);
        // 	}
        // }
        // $clean_timezone = str_replace('_',' ',$clean_timezone); // remove the '_' in city names
        $clean_timezone = User::clean_city($raw_timezone);
        echo "<option value=\"{$raw_timezone}\">(" . $pretty_offset . ") " . $clean_timezone . ' (' . $timezone_abbr . ')</option>';
    }
}
开发者ID:songfarm-david,项目名称:songfarm-jul2015,代码行数:31,代码来源:timezonesFromCountryCode.php

示例7: guessTimeZoneFromOffset

 /**
  * Guess the DateTimeZone for a given offset
  *
  * We first try to find a Etc/GMT* timezone, if that does not exist,
  * we try to find it manually, before falling back to UTC.
  *
  * @param mixed $offset
  * @param bool|int $timestamp
  * @return \DateTimeZone
  */
 protected function guessTimeZoneFromOffset($offset, $timestamp)
 {
     try {
         // Note: the timeZone name is the inverse to the offset,
         // so a positive offset means negative timeZone
         // and the other way around.
         if ($offset > 0) {
             $timeZone = 'Etc/GMT-' . $offset;
         } else {
             $timeZone = 'Etc/GMT+' . abs($offset);
         }
         return new \DateTimeZone($timeZone);
     } catch (\Exception $e) {
         // If the offset has no Etc/GMT* timezone,
         // we try to guess one timezone that has the same offset
         foreach (\DateTimeZone::listIdentifiers() as $timeZone) {
             $dtz = new \DateTimeZone($timeZone);
             $dateTime = new \DateTime();
             if ($timestamp !== false) {
                 $dateTime->setTimestamp($timestamp);
             }
             $dtOffset = $dtz->getOffset($dateTime);
             if ($dtOffset == 3600 * $offset) {
                 return $dtz;
             }
         }
         // No timezone found, fallback to UTC
         \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG);
         return new \DateTimeZone($this->getDefaultTimeZone());
     }
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:41,代码来源:datetimezone.php

示例8: _timezone

 protected function _timezone()
 {
     $element = new Zend_Form_Element_Select('timezone');
     $element->setLabel('Timezone')->addDecorators($this->_decorators)->setRequired(true)->setAttrib('class', 'span4');
     $timezones = array();
     $timezoneIdentifiers = DateTimeZone::listIdentifiers();
     foreach ($timezoneIdentifiers as $timezone) {
         if (preg_match('/^(Africa|America|Antarctica|Asia|Atlantic|Europe|Indian|Pacific)\\//', $timezone)) {
             $ex = explode('/', $timezone);
             $city = isset($ex[2]) ? $ex[1] . ' - ' . $ex[2] : $ex[1];
             $name = $ex[0];
             $timezones[$name][$timezone] = $city;
             $dateTimeZoneGmt = new DateTimeZone('GMT');
             $dateTimeZone = new DateTimeZone($timezone);
             $dateTimeGmt = new DateTime("now", $dateTimeZoneGmt);
             $timeOffset = $dateTimeZone->getOffset($dateTimeGmt);
             $gmt = $timeOffset / 3600;
             if ($gmt == 0) {
                 $gmt = ' 00';
             } elseif ($gmt > 0 && $gmt < 10) {
                 $gmt = '+0' . $gmt;
             } elseif ($gmt >= 10) {
                 $gmt = '+' . $gmt;
             } elseif ($gmt < 0 && $gmt > -10) {
                 $gmt = '-0' . abs($gmt);
             }
             $timezones[$name][$timezone] = substr($timezone, strlen($name) + 1) . ' (GMT ' . $gmt . ':00)';
         }
     }
     $element->addMultiOptions($timezones);
     return $element;
 }
开发者ID:uglide,项目名称:zfcore-transition,代码行数:32,代码来源:Basic.php

示例9: __construct

 public function __construct($tqx, $tq, $tqrt, $tz, $locale, $extra = NULL)
 {
     $this->response = array('status' => 'ok');
     $this->params = array('version' => '0.6', 'sig' => '', 'responseHandler' => 'google.visualization.Query.setResponse');
     if ($extra) {
         foreach ($extra as $key => $value) {
             $this->params[$key] = $value;
         }
     }
     if ($tqx) {
         foreach (explode(';', $tqx) as $kvpair) {
             $kva = explode(':', $kvpair, 2);
             if (count($kva) == 2) {
                 $this->params[$kva[0]] = $kva[1];
             }
         }
     }
     if (get_magic_quotes_gpc()) {
         $tq = stripslashes($tq);
     }
     $this->debug = $extra && $extra['debug'];
     $this->tq = $tq;
     $this->tqrt = $tqrt;
     $this->tz = $tz;
     $this->locale = $locale;
     $timezone = new DateTimeZone($tz);
     $date = new DateTime("", $timezone);
     $this->gmt_offset = $timezone->getOffset($date);
 }
开发者ID:maduhu,项目名称:opengovplatform-beta,代码行数:29,代码来源:vistable.php

示例10: generate_timezone_list

function generate_timezone_list()
{
    static $regions = array(DateTimeZone::AFRICA, DateTimeZone::AMERICA, DateTimeZone::ANTARCTICA, DateTimeZone::ASIA, DateTimeZone::ATLANTIC, DateTimeZone::AUSTRALIA, DateTimeZone::EUROPE, DateTimeZone::INDIAN, DateTimeZone::PACIFIC);
    $timezones = array();
    foreach ($regions as $region) {
        $timezones = array_merge($timezones, DateTimeZone::listIdentifiers($region));
    }
    $timezone_offsets = array();
    foreach ($timezones as $timezone) {
        $tz = new DateTimeZone($timezone);
        $timezone_offsets[$timezone] = $tz->getOffset(new DateTime());
    }
    // sort timezone by timezone name
    ksort($timezone_offsets);
    $timezone_list = array();
    foreach ($timezone_offsets as $timezone => $offset) {
        $offset_prefix = $offset < 0 ? '-' : '+';
        $offset_formatted = gmdate('H:i', abs($offset));
        $pretty_offset = "UTC{$offset_prefix}{$offset_formatted}";
        $t = new DateTimeZone($timezone);
        $c = new DateTime(null, $t);
        $current_time = $c->format('g:i A');
        $timezone_list["({$pretty_offset}) {$timezone}"] = "{$timezone} - {$current_time} ({$pretty_offset})";
    }
    return $timezone_list;
}
开发者ID:arnavmaiti,项目名称:websitebuilder,代码行数:26,代码来源:site.php

示例11: timezonesFromCountryCode

function timezonesFromCountryCode($country_code, $city_name)
{
    $dt = new DateTime();
    // create a list of timezones based on that country code..
    $timezones = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country_code);
    $timezone_offset = [];
    // instantiate timezone_offset array
    foreach ($timezones as $timezone) {
        $tz = new DateTimeZone($timezone);
        $timezone_offset[$timezone] = $tz->getOffset(new DateTime());
    }
    // sort by offset
    arsort($timezone_offset);
    // format display of timezone and offset
    foreach ($timezone_offset as $raw_timezone => $offset) {
        $dt->setTimezone(new DateTimeZone($raw_timezone));
        $timezone_abbr = $dt->format('T');
        $offset_prefix = $offset < 0 ? '-' : '+';
        $offset_formatted = gmdate('H:i', abs($offset));
        $pretty_offset = "UTC{$offset_prefix}{$offset_formatted}";
        // clean up raw timezone
        $clean_timezone = User::cleanCity($raw_timezone);
        // echo back options to a select dropdown on workshop.php
        if ($city_name == $clean_timezone) {
            echo "<option value=\"{$raw_timezone}\" selected>(" . $pretty_offset . ") " . $clean_timezone . ' (' . $timezone_abbr . ')</option>';
        } else {
            echo "<option value=\"{$raw_timezone}\">(" . $pretty_offset . ") " . $clean_timezone . ' (' . $timezone_abbr . ')</option>';
        }
    }
    // end of: foreach
}
开发者ID:songfarm-david,项目名称:Songfarm,代码行数:31,代码来源:timezones_from_country_code.php

示例12: UTCTimeZoneOffset

 /**
  * Get offset between a time zone and UTC time zone in seconds.
  *
  * @return integer
  */
 public function UTCTimeZoneOffset() : int
 {
     $originDateTime = new \DateTime('now', $this);
     $utcTimeZone = new \DateTimeZone('UTC');
     $utcDateTime = new \DateTime('now', $utcTimeZone);
     return $utcTimeZone->getOffset($utcDateTime) - $this->getOffset($originDateTime);
 }
开发者ID:dragosprotung,项目名称:stc-core,代码行数:12,代码来源:DateTimeZone.php

示例13: getTimeZoneOffset

 public static function getTimeZoneOffset()
 {
     $oTimeZoneUtc = new DateTimeZone('UTC');
     $oTimeZoneLocal = new DateTimeZone(date_default_timezone_get());
     $oDateTime = new DateTime('now', $oTimeZoneUtc);
     return $oTimeZoneLocal->getOffset($oDateTime);
 }
开发者ID:rali-udem,项目名称:JSrealB,代码行数:7,代码来源:Date.php

示例14: timezoneList

 public static function timezoneList()
 {
     $tmp = array();
     $timezone_identifiers_list = timezone_identifiers_list();
     foreach ($timezone_identifiers_list as $timezone_identifier) {
         $date_time_zone = new DateTimeZone($timezone_identifier);
         $date_time = new DateTime('now', $date_time_zone);
         $hours = floor($date_time_zone->getOffset($date_time) / 3600);
         $mins = floor(($date_time_zone->getOffset($date_time) - $hours * 3600) / 60);
         $hours = 'GMT' . ($hours < 0 ? $hours : '+' . $hours);
         $mins = $mins > 0 ? $mins : '0' . $mins;
         $text = str_replace("_", " ", $timezone_identifier);
         $tmp[$text . ' (' . $hours . ':' . $mins . ')'] = $timezone_identifier;
     }
     return $tmp;
 }
开发者ID:joryphillips,项目名称:bludit,代码行数:16,代码来源:date.class.php

示例15: getTimezoneOffset

 public static function getTimezoneOffset($remoteTz, $originTz)
 {
     if (is_null($originTz)) {
         $originTz = date_default_timezone_get();
         if (!is_string($originTz)) {
             return false;
         }
     }
     if (is_null($remoteTz)) {
         $remoteTz = date_default_timezone_get();
         if (!is_string($remoteTz)) {
             return false;
         }
     }
     if (get_class($remoteTz) == 'DateTimeZone') {
         $remoteDtz = $remoteTz;
     } else {
         $remoteDtz = new DateTimeZone($remoteTz);
     }
     if (get_class($originTz) == 'DateTimeZone') {
         $originDtz = $originTz;
     } else {
         $originDtz = new DateTimeZone($originTz);
     }
     $originDt = new DateTime('now', $originDtz);
     $remoteDt = new DateTime('now', $remoteDtz);
     return $originDtz->getOffset($originDt) - $remoteDtz->getOffset($remoteDt);
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:28,代码来源:DateTime.php


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