本文整理汇总了PHP中JDate::getOffset方法的典型用法代码示例。如果您正苦于以下问题:PHP JDate::getOffset方法的具体用法?PHP JDate::getOffset怎么用?PHP JDate::getOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JDate
的用法示例。
在下文中一共展示了JDate::getOffset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserTime
/**
* This will return the user timezone
* @param int $user_id id of the user
* @param String $forDisplay get the display, if true then return value will be formatted to the proper display
* @return String depends on the value of format
*/
public static function getUserTime($user_id = null, $forDisplay = false)
{
$config = new JXConfig();
$user = JFactory::getUser($user_id);
// First load account setting (if any) timezone to override timezone in language file
$defaultTz = $config->getTimezone() != '' ? $config->getTimezone() : JText::_('JXLIB_DEFAULT_TIMEZONE');
$my = !$user instanceof JUser && !$user instanceof JXUser ? JXFactory::getUser() : $user;
$timeZoneStr = $my->getParam('timezone');
// Second load user personalize timezone (if any) to override system default timezone
$timeZoneStr = empty($timeZoneStr) ? $defaultTz : $timeZoneStr;
$tz = new DateTimeZone($timeZoneStr);
$date2 = new JDate('now', $tz);
$offset = $date2->getOffset() / 3600;
$date = new JDate();
$date->setOffset($offset);
$xdate = new JXDate();
/* if the value want to be used as display purposes */
if ($forDisplay) {
return $xdate->formatDate($date);
} else {
return $xdate->format($date);
}
}
示例2: get
/**
*
* $range array('month' => 2)
*/
public static function get($actions, $user_id, $group_id, $range, $group_by)
{
if ($group_by == 'hour') {
// todo: db datetime is server utc, might need to calculate for offset
$config = new JXConfig();
$defaultTz = $config->getTimezone() != '' ? $config->getTimezone() : JText::_('JXLIB_DEFAULT_TIMEZONE');
$my = JXFactory::getUser($user_id);
$myTimeZone = $my->getParam('timezone');
// Second load user personalize timezone (if any) to override system default timezone
$timeZoneStr = empty($myTimeZone) ? $defaultTz : $myTimeZone;
$tz = new DateTimeZone($timeZoneStr);
$date2 = new JDate('now', $tz);
$offset = $date2->getOffset() / 3600;
} else {
$offset = 0;
}
$result = self::getDbRecord($actions, $user_id, $group_id, $range, $group_by, $offset);
return self::formulateData($result, $group_by, $offset);
}
示例3: formatDate
/**
* Return standardized formatted date
* NOTE: FOR TEMPLATE DISPLAY PURPOSE ONLY!!! DO NOT USE FOR DB QUERIES
* Also use only for server generated time, NOT
*/
static function formatDate($date, $long = self::LONG_DATE_FORMAT, $user = null)
{
// return original input date that cannot be processed
if (strtotime($date) === false) {
return $date;
}
$config = new JXConfig();
// First load account setting (if any) timezone to override timezone in language file
$defaultTz = $config->getTimezone() != '' ? $config->getTimezone() : JText::_('JXLIB_DEFAULT_TIMEZONE');
$my = !$user instanceof JUser && !$user instanceof JXUser ? JXFactory::getUser() : $user;
$timeZoneStr = $my->getParam('timezone');
// Second load user personalize timezone (if any) to override system default timezone
$timeZoneStr = empty($timeZoneStr) ? $defaultTz : $timeZoneStr;
$tz = new DateTimeZone($timeZoneStr);
if ($date instanceof JDate) {
$date = $date->format('Y-m-d h:i:s');
}
$datenow = new JDate('now', $tz);
$offset = $datenow->getOffset() / 3600;
$date = new JDate($date);
$date->setOffset($offset);
$dateStr = $long == self::LONG_DATE_FORMAT ? $date->format(JText::_('JXLIB_DATE_FORMAT'), true) : $date->format(JText::_('JXLIB_DATE_SHORT_FORMAT'), true);
if ($long == self::LONG_DATE_FORMAT) {
// Test for today
$dmy = $datenow->format(JText::_('JXLIB_DATE_DMY'), true);
$dateStr = str_replace($dmy, JText::_('JXLIB_DATE_TODAY'), $dateStr);
// Test for yesterday
$datenow->modify('-1 day');
$dmy = $datenow->format(JText::_('JXLIB_DATE_DMY'), true);
$dateStr = str_replace($dmy, JText::_('JXLIB_DATE_YESTERDAY'), $dateStr);
}
return $dateStr;
}
示例4: getOffset
public function getOffset($hours = false)
{
return C_JOOMLA_15 == 1 ? parent::getOffset() : parent::getOffsetFromGMT($hours);
}