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


PHP XoopsLocale::getFormatToday方法代码示例

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


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

示例1: formatTimestamp

 /**
  * Function to display formatted times in user timezone
  * Setting $timeoffset to null (by default) will skip timezone calculation for user, using default timezone instead, which is a MUST for cached contents
  *
  * @param        $time
  * @param string $format
  * @param string $timeoffset
  *
  * @return string
  */
 public static function formatTimestamp($time, $format = 'l', $timeoffset = null)
 {
     $xoops = Xoops::getInstance();
     $format_copy = $format;
     $format = strtolower($format);
     if ($format == 'rss' || $format == 'r') {
         $TIME_ZONE = '';
         if ($xoops->getConfig('server_TZ')) {
             $server_TZ = abs((int) ($xoops->getConfig('server_TZ') * 3600.0));
             $prefix = $xoops->getConfig('server_TZ') < 0 ? ' -' : ' +';
             $TIME_ZONE = $prefix . date('Hi', $server_TZ);
         }
         $date = gmdate('D, d M Y H:i:s', (int) $time) . $TIME_ZONE;
         return $date;
     }
     if (($format == 'elapse' || $format == 'e') && $time < time()) {
         $elapse = time() - $time;
         if ($days = floor($elapse / (24 * 3600))) {
             $num = $days > 1 ? sprintf(XoopsLocale::LF_AGO_DAYS, $days) : XoopsLocale::LF_AGO_ONE_DAY;
         } elseif ($hours = floor($elapse % (24 * 3600) / 3600)) {
             $num = $hours > 1 ? sprintf(XoopsLocale::LF_AGO_HOURS, $hours) : XoopsLocale::LF_AGO_ONE_HOUR;
         } elseif ($minutes = floor($elapse % 3600 / 60)) {
             $num = $minutes > 1 ? sprintf(XoopsLocale::LF_AGO_MINUTES, $minutes) : XoopsLocale::LF_AGO_ONE_MINUTE;
         } else {
             $seconds = $elapse % 60;
             $num = $seconds > 1 ? sprintf(XoopsLocale::LF_AGO_SECONDS, $seconds) : sprintf(XoopsLocale::LF_AGO_ONE_SECOND);
         }
         return $num;
     }
     // disable user timezone calculation and use default timezone,
     // for cache consideration
     if ($timeoffset === null) {
         $timeoffset = $xoops->getConfig('default_TZ') == '' ? '0.0' : $xoops->getConfig('default_TZ');
     }
     $usertimestamp = $xoops->getUserTimestamp($time, $timeoffset);
     switch ($format) {
         case 's':
             $datestring = self::getFormatShortDate();
             break;
         case 'm':
             $datestring = self::getFormatMediumDate();
             break;
         case 'mysql':
             $datestring = 'Y-m-d H:i:s';
             break;
         case 'l':
             $datestring = self::getFormatLongDate();
             break;
         case 'c':
         case 'custom':
             static $current_timestamp, $today_timestamp, $monthy_timestamp;
             if (!isset($current_timestamp)) {
                 $current_timestamp = $xoops->getUserTimestamp(time(), $timeoffset);
             }
             if (!isset($today_timestamp)) {
                 $today_timestamp = mktime(0, 0, 0, gmdate('m', $current_timestamp), gmdate('d', $current_timestamp), gmdate('Y', $current_timestamp));
             }
             if (abs($elapse_today = $usertimestamp - $today_timestamp) < 24 * 60 * 60) {
                 $datestring = $elapse_today > 0 ? XoopsLocale::getFormatToday() : XoopsLocale::getFormatYesterday();
             } else {
                 if (!isset($monthy_timestamp)) {
                     $monthy_timestamp[0] = mktime(0, 0, 0, 0, 0, gmdate('Y', $current_timestamp));
                     $monthy_timestamp[1] = mktime(0, 0, 0, 0, 0, gmdate('Y', $current_timestamp) + 1);
                 }
                 if ($usertimestamp >= $monthy_timestamp[0] && $usertimestamp < $monthy_timestamp[1]) {
                     $datestring = self::getFormatMonthDay();
                 } else {
                     $datestring = self::getFormatYearMonthDay();
                 }
             }
             break;
         default:
             if ($format != '') {
                 $datestring = $format_copy;
             } else {
                 $datestring = self::getFormatLongDate();
             }
             break;
     }
     return ucfirst(gmdate($datestring, $usertimestamp));
 }
开发者ID:redmexico,项目名称:XoopsCore,代码行数:91,代码来源:Abstract.php


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