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


PHP DateTime::getOffset方法代码示例

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


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

示例1: get_current_date_start_time

 public function get_current_date_start_time($country_code = 'BD')
 {
     $time_zone_array = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country_code);
     $dateTimeZone = new DateTimeZone($time_zone_array[0]);
     $dateTime = new DateTime("now", $dateTimeZone);
     $unix_current_time = now() + $dateTime->getOffset();
     $human_current_time = unix_to_human($unix_current_time);
     $human_current_time_array = explode(" ", $human_current_time);
     $human_current_date = $human_current_time_array[0];
     $human_current_date_start_time = $human_current_date . ' 00:00 AM';
     $unix_current_date_start_time = human_to_unix($human_current_date_start_time);
     return $unix_current_date_start_time - $dateTime->getOffset();
 }
开发者ID:bdlions,项目名称:webserver,代码行数:13,代码来源:Date_utils.php

示例2: init

 /**
  * Required plugin startup method
  */
 public function init()
 {
     self::$instance = $this;
     $this->rc = rcube::get_instance();
     // set user's timezone
     try {
         $this->timezone = new DateTimeZone($this->rc->config->get('timezone', 'GMT'));
     } catch (Exception $e) {
         $this->timezone = new DateTimeZone('GMT');
     }
     $now = new DateTime('now', $this->timezone);
     $this->gmt_offset = $now->getOffset();
     $this->dst_active = $now->format('I');
     $this->timezone_offset = $this->gmt_offset / 3600 - $this->dst_active;
     $this->add_texts('localization/', false);
     // include client scripts and styles
     if ($this->rc->output) {
         // add hook to display alarms
         $this->add_hook('refresh', array($this, 'refresh'));
         $this->register_action('plugin.alarms', array($this, 'alarms_action'));
         $this->register_action('plugin.expand_attendee_group', array($this, 'expand_attendee_group'));
     }
     // proceed initialization in startup hook
     $this->add_hook('startup', array($this, 'startup'));
 }
开发者ID:Fneufneu,项目名称:libcalendaring,代码行数:28,代码来源:libcalendaring.php

示例3: getChangeTime

 /**
  *
  * Possible bug was also detected: date_sunrise() seems to return date of the previous day:
  * https://bugs.php.net/bug.php?id=53148
  *
  * To avoid issues, only compare day agnostic formats:  $dt->format('Hi')
  *
  * @param \DateTime $dateTime
  * @param $method
  *
  * @return \DateTime
  */
 private function getChangeTime(\DateTime $dateTime, $method)
 {
     $location = $dateTime->getTimezone()->getLocation();
     $horizonShift = new \DateTime('now', $dateTime->getTimezone());
     $horizonShift->setTimestamp($method($dateTime->getTimestamp(), SUNFUNCS_RET_TIMESTAMP, $location['latitude'], $location['longitude'], ini_get("date.sunrise_zenith"), $dateTime->getOffset() / 3600));
     return $horizonShift;
 }
开发者ID:pierswarmers,项目名称:mandate,代码行数:19,代码来源:SunlightRuleBase.php

示例4: GET

 public function GET()
 {
     $policy = new Policy_LoggedIn($this->app);
     $app = Config::get('app');
     $userid = $policy->getData();
     $request = $this->app->request();
     if (!$userid) {
         throw new Exception_Api("Unable to authenticate.");
     }
     $days_back = trim($request->get('days_back'));
     if (!is_numeric($days_back) && $days_back != 'all' && $days_back != 'ytd') {
         throw new Exception_Api('Missing or invalid days_back field.');
     }
     $mapper = new Mapper_Settings();
     $mapper->updateSettingForUserid($userid, 'default_view', $days_back);
     $settings = $mapper->getFilteredSettingsByUserid($userid);
     $serverDateTimeZone = new DateTimeZone($app->default_timezone);
     $userDateTimeZone = new DateTimeZone($settings['timezone']);
     $serverDateTime = new DateTime("now", $serverDateTimeZone);
     $userDateTime = new DateTime("now", $userDateTimeZone);
     $tzDiff = $userDateTime->getOffset() - $serverDateTime->getOffset();
     $tzDiff = $tzDiff / (60 * 60);
     $weight_mapper = new Mapper_Weight();
     $weights = $weight_mapper->getWeightsForUser($userid, $days_back);
     $formatted_weights = array();
     foreach ($weights as $weight) {
         $formatted_weights[] = array('date' => $weight['create_time'], 'weight' => $weight['weight'], 'comment' => htmlentities($weight['comment']));
     }
     return array('data' => $formatted_weights, 'units' => $app->weight_units, 'tz_offset' => $tzDiff);
 }
开发者ID:yisrael1981,项目名称:weight,代码行数:30,代码来源:Weights.php

示例5: connecting

 public function connecting()
 {
     $now = new DateTime();
     $mins = $now->getOffset() / 60;
     $sgn = $mins < 0 ? -1 : 1;
     $mins = abs($mins);
     $hrs = floor($mins / 60);
     $mins -= $hrs * 60;
     $offset = sprintf('%+d:%02d', $hrs * $sgn, $mins);
     // @formatter:off
     $this->dsn = $this->parametro['MotorBD'] . ":host=" . $this->parametro['HostBD'] . ";dbname=" . $this->parametro['NameBD'];
     // @formatter:on
     if (!self::$PDOInstance) {
         try {
             self::$PDOInstance = new PDO($this->dsn, $this->parametro['UserBD'], $this->parametro['PassBD']);
             // self::$PDOInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             self::$PDOInstance->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES utf8");
             self::$PDOInstance->setAttribute(PDO::ATTR_PERSISTENT, false);
             self::$PDOInstance->exec("SET time_zone = '{$offset}';");
         } catch (PDOException $e) {
             header('HTTP/1.0 500 Internal Server Error');
             // $this->logs->error("Error al conectar: ", $e->getMessage());
             echo "Error al conectar: " . $e->getMessage() . "<br/>";
             exit;
         }
     }
 }
开发者ID:rafaelurrutia,项目名称:bmonitor-y-bi,代码行数:27,代码来源:libs.connect.php

示例6: timezones

function timezones()
{
    $list = DateTimeZone::listIdentifiers();
    $data = array();
    foreach ($list as $id => $zone) {
        $now = new DateTime(null, new DateTimeZone($zone));
        $offset = $now->getOffset();
        $offset_round = round(abs($offset / 3600), 2);
        $minutes = fmod($offset_round, 1);
        if ($minutes == 0) {
            $offset_label = $offset_round . '&nbsp;&nbsp;';
        } elseif ($minutes == 0.5) {
            $offset_label = (int) $offset_round . '.30';
        } elseif ($minutes == 0.75) {
            $offset_label = (int) $offset_round . '.45';
        }
        $sign = $offset > 0 ? '+' : '-';
        if ($offset == 0) {
            $sign = ' ';
            $offset = '';
        }
        $label = 'GMT' . $sign . $offset_label . '&nbsp;' . $zone;
        $data[$offset][$zone] = array('offset' => $offset, 'label' => $label, 'timezone_id' => $zone);
    }
    ksort($data);
    $timezones = array();
    foreach ($data as $offsets) {
        ksort($offsets);
        foreach ($offsets as $zone) {
            $timezones[] = $zone;
        }
    }
    return $timezones;
}
开发者ID:hackiosa,项目名称:anchor-cms,代码行数:34,代码来源:run.php

示例7: _setDatabaseOptions

 private function _setDatabaseOptions()
 {
     if (is_object(Config::getInstance()->getValue('database'))) {
         if (Config::getInstance()->getValue('database')->hasValue('charset')) {
             $lCharset = Config::getInstance()->getValue('database')->getValue('charset');
         } else {
             trigger_error('Warning undefined charset database. By default charset is set to \'utf8\' ');
             $lCharset = 'utf8';
         }
         if (Config::getInstance()->getValue('database')->hasValue('timezone')) {
             $lTimezone = Config::getInstance()->getValue('database')->getValue('timezone');
         } else {
             trigger_error('Warning undefined timezone database. By default charset is set to \'utf8\' ');
             $lTimezone = 'UTC';
         }
     } else {
         trigger_error('Warning undefined database options connections');
         $lCharset = 'utf8';
         $lTimezone = 'UTC';
     }
     $lDate = new \DateTime('now', new \DateTimeZone($lTimezone));
     $lTotalOffsetSeconds = $lDate->getOffset();
     $lOffsetOperator = $lTotalOffsetSeconds >= 0 ? '+' : '-';
     $lOffsetHours = floor(abs($lTotalOffsetSeconds) / 3600);
     $lOffsetMinutes = floor(abs($lTotalOffsetSeconds) % 3600 / 60);
     $lOffset = $lOffsetOperator . $lOffsetHours . ':' . $lOffsetMinutes;
     $this->mDbHandle->exec("SET NAMES {$lCharset};");
     $this->mDbHandle->exec("SET time_zone = '{$lOffset}';");
 }
开发者ID:jeanphilippe-p,项目名称:ObjectManagerLib,代码行数:29,代码来源:DatabaseController.php

示例8: getZoneOffset

 /** get time zone offset
  * 
  * @param string $zone
  */
 function getZoneOffset($zone)
 {
     $a = new DateTimeZone($zone);
     $b = new DateTime("now", $a);
     $offset = $b->getOffset() / 3600;
     return $offset;
 }
开发者ID:optimosolution,项目名称:marhk,代码行数:11,代码来源:helper.php

示例9: connect

 /**
  * Establishing database connection
  * @return database connection handler
  */
 function connect()
 {
     include_once dirname(__FILE__) . '/Config.php';
     //Setting timezone to PHP
     date_default_timezone_set(TIMEZONE);
     // Connecting to mysql database
     $this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
     //Setting time zone to MySQL
     $now = new DateTime();
     $mins = $now->getOffset() / 60;
     $sgn = $mins < 0 ? -1 : 1;
     $mins = abs($mins);
     $hrs = floor($mins / 60);
     $mins -= $hrs * 60;
     $offset = sprintf('%+d:%02d', $hrs * $sgn, $mins);
     $stmt = $this->conn->prepare("SET time_zone='{$offset}'");
     $stmt->execute();
     $stmt->close();
     //echo "offset=".$offset."\n";
     // Check for database connection error
     if (mysqli_connect_errno()) {
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }
     // returing connection resource
     return $this->conn;
 }
开发者ID:Igorpi25,项目名称:Server,代码行数:30,代码来源:DbConnect.php

示例10: __construct

 public function __construct()
 {
     $timeNow = time();
     //test
     $checkOffset = new \DateTime(date('d.m.Y', $timeNow), new \DateTimeZone(self::$tz));
     $calcSumWin = $checkOffset->getOffset();
     $this->nowTime = strtotime(date('d.m.Y H:i', $timeNow)) + $calcSumWin;
     if (\OC::$server->getSession()->get('public_link_token')) {
         $linkItem = \OCP\Share::getShareByToken(\OC::$server->getSession()->get('public_link_token', false));
         if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
             if ($linkItem['item_type'] === App::SHARECALENDAR) {
                 $sPrefix = App::SHARECALENDARPREFIX;
             }
             if ($linkItem['item_type'] === App::SHAREEVENT) {
                 $sPrefix = App::SHAREEVENTPREFIX;
             }
             if ($linkItem['item_type'] === App::SHARETODO) {
                 $sPrefix = App::SHARETODOPREFIX;
             }
             $itemSource = App::validateItemSource($linkItem['item_source'], $sPrefix);
             $rootLinkItem = Calendar::find($itemSource);
             $this->aCalendars[] = $rootLinkItem;
         }
     } else {
         if (\OCP\User::isLoggedIn()) {
             $this->aCalendars = Calendar::allCalendars(\OCP\User::getUser());
             $this->checkAlarm();
         }
     }
 }
开发者ID:Rotzbua,项目名称:calendarplus,代码行数:30,代码来源:alarm.php

示例11: UtcTimestamp

 static function UtcTimestamp()
 {
     //Timestamp as UTC
     $config = JFactory::getConfig();
     $tz = new DateTime('now', new DateTimeZone($config->get('offset')));
     return time() - $tz->getOffset();
 }
开发者ID:TFToto,项目名称:playjoom-builds,代码行数:7,代码来源:helper.php

示例12: init

 /**
  * Required plugin startup method
  */
 public function init()
 {
     self::$instance = $this;
     $this->rc = rcube::get_instance();
     // set user's timezone
     try {
         $this->timezone = new DateTimeZone($this->rc->config->get('timezone', 'UTC'));
     } catch (Exception $e) {
         $this->timezone = new DateTimeZone('UTC');
     }
     $now = new DateTime('now', $this->timezone);
     $this->gmt_offset = $now->getOffset();
     $this->dst_active = $now->format('I');
     $this->timezone_offset = $this->gmt_offset / 3600 - $this->dst_active;
     $this->add_texts('localization/', false);
     // include client scripts and styles
     if ($this->rc->output) {
         if ($this->rc->output->type == 'html') {
             $this->rc->output->set_env('libcal_settings', $this->load_settings());
             $this->rc->output->add_header(html::tag('script', array('type' => 'text/javascript', 'src' => 'plugins/libgpl/libcalendaring/libcalendaring.js')));
             $this->include_stylesheet($this->local_skin_path() . '/libcal.css');
         }
         // add hook to display alarms
         $this->add_hook('refresh', array($this, 'refresh'));
         $this->register_action('plugin.alarms', array($this, 'alarms_action'));
     }
 }
开发者ID:haision,项目名称:myroundcube,代码行数:30,代码来源:libcalendaring.php

示例13: ShowInformationPage

function ShowInformationPage()
{
    global $LNG, $CONF, $USER;
    if (file_exists(ini_get('error_log'))) {
        $Lines = count(file(ini_get('error_log')));
    } else {
        $Lines = 0;
    }
    try {
        $dateTimeZoneServer = new DateTimeZone(Config::get('timezone'));
    } catch (Exception $e) {
        $dateTimeZoneServer = new DateTimeZone(date_default_timezone_get());
    }
    try {
        $dateTimeZoneUser = new DateTimeZone($USER['timezone']);
    } catch (Exception $e) {
        $dateTimeZoneUser = new DateTimeZone(date_default_timezone_get());
    }
    try {
        $dateTimeZonePHP = new DateTimeZone(ini_get('date.timezone'));
    } catch (Exception $e) {
        $dateTimeZonePHP = new DateTimeZone(date_default_timezone_get());
    }
    $dateTimeServer = new DateTime("now", $dateTimeZoneServer);
    $dateTimeUser = new DateTime("now", $dateTimeZoneUser);
    $dateTimePHP = new DateTime("now", $dateTimeZonePHP);
    $template = new template();
    $template->assign_vars(array('info_information' => sprintf($LNG['info_information'], 'http://tracker.2moons.cc/'), 'info' => $_SERVER['SERVER_SOFTWARE'], 'vPHP' => PHP_VERSION, 'vAPI' => PHP_SAPI, 'vGame' => Config::get('VERSION'), 'vMySQLc' => $GLOBALS['DATABASE']->getVersion(), 'vMySQLs' => $GLOBALS['DATABASE']->getServerVersion(), 'root' => $_SERVER['SERVER_NAME'], 'gameroot' => $_SERVER['SERVER_NAME'] . str_replace('/admin.php', '', $_SERVER['PHP_SELF']), 'json' => function_exists('json_encode') ? 'Ja' : 'Nein', 'bcmath' => extension_loaded('bcmath') ? 'Ja' : 'Nein', 'curl' => extension_loaded('curl') ? 'Ja' : 'Nein', 'browser' => $_SERVER['HTTP_USER_AGENT'], 'safemode' => ini_get('safe_mode') ? 'Ja' : 'Nein', 'memory' => ini_get('memory_limit'), 'suhosin' => ini_get('suhosin.request.max_value_length') ? 'Ja' : 'Nein', 'log_errors' => ini_get('log_errors') ? 'Aktiv' : 'Inaktiv', 'errorlog' => ini_get('error_log'), 'errorloglines' => $Lines, 'php_tz' => $dateTimePHP->getOffset() / 3600, 'conf_tz' => $dateTimeServer->getOffset() / 3600, 'user_tz' => $dateTimeUser->getOffset() / 3600));
    $template->show('ShowInformationPage.tpl');
}
开发者ID:fuding,项目名称:Antaris,代码行数:30,代码来源:ShowInformationPage.php

示例14: connect_pdo

function connect_pdo($config)
{
    // computing timezone difference with gmt:
    // http://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/
    $now = new DateTime();
    $mins = $now->getOffset() / 60;
    $sgn = $mins < 0 ? -1 : 1;
    $mins = abs($mins);
    $hrs = floor($mins / 60);
    $mins -= $hrs * 60;
    $offset = sprintf('%+d:%02d', $hrs * $sgn, $mins);
    try {
        $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
        $pdo_options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES utf8";
        $connexionString = "mysql:host=" . $config->db->mysql->host . ";dbname=" . $config->db->mysql->database;
        if ($config->db->mysql->logged) {
            $db = new LoggedPDO($connexionString, $config->db->mysql->user, $config->db->mysql->password, $pdo_options);
        } else {
            $db = new PDO($connexionString, $config->db->mysql->user, $config->db->mysql->password, $pdo_options);
        }
        $db->exec("SET time_zone='" . $offset . "';");
    } catch (Exception $e) {
        die("Erreur : " . $e->getMessage());
    }
    return $db;
}
开发者ID:BebrasTeam,项目名称:BebrasContestServer,代码行数:26,代码来源:connect.php

示例15: getAllTimeZones

 public static function getAllTimeZones()
 {
     $file = dirname(__FILE__) . "/data/timezones.php";
     if (file_exists($file)) {
         return include $file;
     }
     $data = DateTimeZone::listIdentifiers();
     $time_zones = array();
     foreach ($data as $time_zone_id) {
         $t = explode('/', $time_zone_id, 2);
         $date_time = new DateTime('now');
         $tz = new DateTimeZone($time_zone_id);
         $date_time->setTimezone($tz);
         $offset = (double) $date_time->getOffset() / 3600;
         $group = count($tz->getTransitions(strtotime('-1 year'), time()));
         if (isset($t[1])) {
             $time_zones[$offset][$group][$t[0]][] = $t[1];
         } else {
             $time_zones[$offset][$group][''][] = $t[0];
         }
     }
     ksort($time_zones);
     $result = array();
     foreach ($time_zones as $offset => $group_offset_zones) {
         foreach ($group_offset_zones as $group => $offset_zones) {
             if ($offset >= 10) {
                 $str_offset = '+' . $offset;
             } elseif ($offset >= 0 && $offset < 10) {
                 $str_offset = '+0' . $offset;
             } elseif ($offset < 0 && $offset > -10) {
                 $str_offset = '−0' . abs($offset);
             } elseif ($offset <= -10) {
                 $str_offset = '−' . abs($offset);
             }
             foreach ($offset_zones as $continent => $zones) {
                 if (count($zones) <= 5) {
                     $result[($continent ? $continent . "/" : '') . $zones[0]] = array($str_offset, $zones);
                 } else {
                     $i = 0;
                     $n = count($zones);
                     while ($i < $n) {
                         $tmp = array();
                         for ($j = 0; $j < 5 && $i + $j < $n; $j++) {
                             $z = $zones[$i + $j];
                             if (($k = strpos($z, '/')) !== false) {
                                 $z = substr($z, $k + 1);
                             }
                             $tmp[] = $z;
                         }
                         $result[$continent . "/" . $zones[$i]] = array($str_offset, $tmp);
                         $i += 5;
                     }
                 }
             }
         }
     }
     waUtils::varExportToFile($result, dirname(__FILE__) . "/data/timezones.php");
     return $result;
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:59,代码来源:waDateTime.class.php


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