當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TTDate::time_zone方法代碼示例

本文整理匯總了PHP中TTDate::time_zone方法的典型用法代碼示例。如果您正苦於以下問題:PHP TTDate::time_zone方法的具體用法?PHP TTDate::time_zone怎麽用?PHP TTDate::time_zone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TTDate的用法示例。


在下文中一共展示了TTDate::time_zone方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setTimeZone

 public static function setTimeZone($time_zone = NULL)
 {
     global $config_vars;
     $time_zone = Misc::trimSortPrefix(trim($time_zone));
     //Default to system local timezone if no timezone is specified.
     if ($time_zone == '') {
         if (isset($config_vars['other']['system_timezone'])) {
             $time_zone = $config_vars['other']['system_timezone'];
         } else {
             //$time_zone = 'GMT';
             $time_zone = date('e');
         }
     }
     if ($time_zone == self::$time_zone) {
         Debug::text('TimeZone already set to: ' . $time_zone, __FILE__, __LINE__, __METHOD__, 10);
         return TRUE;
     }
     if ($time_zone != '') {
         Debug::text('Setting TimeZone: ' . $time_zone, __FILE__, __LINE__, __METHOD__, 10);
         self::$time_zone = $time_zone;
         @date_default_timezone_set($time_zone);
         putenv('TZ=' . $time_zone);
         global $db;
         if (isset($db) and is_object($db) and strncmp($db->databaseType, 'mysql', 5) == 0) {
             if (@$db->Execute('SET SESSION time_zone=\'' . $time_zone . '\'') == FALSE) {
                 return FALSE;
             }
         }
         return TRUE;
     } else {
         //PHP doesn't have a unsetenv(), so this will cause the system to default to UTC.
         //If we don't do this then looping over users and setting timezones, if a user
         //doesn't have a timezone set, it will cause them to use the previous users timezone.
         //This way they at least use UTC and hopefully the issue will stand out more.
         //date_default_timezone_set( '' );
         putenv('TZ=');
     }
     return FALSE;
 }
開發者ID:J-P-Hanafin,項目名稱:TimeTrex-1,代碼行數:39,代碼來源:TTDate.class.php

示例2: setTimeZone

 public static function setTimeZone($time_zone = NULL)
 {
     global $config_vars, $current_user_prefs;
     $time_zone = Misc::trimSortPrefix(trim($time_zone));
     //Default to system local timezone if no timezone is specified.
     if ($time_zone == '' or strtolower($time_zone) == 'system/localtime') {
         //System/Localtime is an invalid timezone, so default to GMT instead.
         if (isset($current_user_prefs) and is_object($current_user_prefs)) {
             //When TTDate is called from the API directly, its not called statically, so
             //this forces __construct() to call setTimeZone and for the timezone to be set back to the system defined timezone after
             //$current_user->getUserPreferenceObject()->setDateTimePreferences(); is called.
             //This checks to see if a user is logged in and uses their own preferences instead.
             $time_zone = $current_user_prefs->getTimeZone();
         } elseif (isset($config_vars['other']['system_timezone'])) {
             $time_zone = $config_vars['other']['system_timezone'];
         } else {
             //$time_zone = date('e'); //Newer versions of PHP return System/Localtime which is invalid, so force to GMT instead
             $time_zone = 'GMT';
         }
     }
     if ($time_zone == self::$time_zone) {
         Debug::text('TimeZone already set to: ' . $time_zone, __FILE__, __LINE__, __METHOD__, 10);
         return TRUE;
     }
     if ($time_zone != '') {
         Debug::text('Setting TimeZone: ' . $time_zone, __FILE__, __LINE__, __METHOD__, 10);
         global $db;
         if (isset($db) and is_object($db) and strncmp($db->databaseType, 'mysql', 5) == 0) {
             if (@$db->Execute('SET SESSION time_zone=' . $db->qstr($time_zone)) == FALSE) {
                 return FALSE;
             }
         }
         //Set timezone AFTER MySQL query above, so if it fails we don't set the timezone below at all.
         self::$time_zone = $time_zone;
         @date_default_timezone_set($time_zone);
         putenv('TZ=' . $time_zone);
         return TRUE;
     } else {
         //PHP doesn't have a unsetenv(), so this will cause the system to default to UTC.
         //If we don't do this then looping over users and setting timezones, if a user
         //doesn't have a timezone set, it will cause them to use the previous users timezone.
         //This way they at least use UTC and hopefully the issue will stand out more.
         //date_default_timezone_set( '' );
         putenv('TZ=');
     }
     return FALSE;
 }
開發者ID:alachaum,項目名稱:timetrex,代碼行數:47,代碼來源:TTDate.class.php


注:本文中的TTDate::time_zone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。