本文整理汇总了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;
}
示例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;
}