• discuz函数dgmdate


    function dgmdate($timestamp, $format = 'dt', $timeoffset = '9999', $uformat = '') {
        global $_G;
        $format == 'u' && !$_G['setting']['dateconvert'] && $format = 'dt';
        static $dformat, $tformat, $dtformat, $offset, $lang;
        if($dformat === null) {
            $dformat = getglobal('setting/dateformat');
            $tformat = getglobal('setting/timeformat');
            $dtformat = $dformat.' '.$tformat;
            $offset = getglobal('member/timeoffset');
            $sysoffset = getglobal('setting/timeoffset');
            $offset = $offset == 9999 ? ($sysoffset ? $sysoffset : 0) : $offset;
            $lang = lang('core', 'date');
        }
        $timeoffset = $timeoffset == 9999 ? $offset : $timeoffset;
        $timestamp += $timeoffset * 3600;
        $format = empty($format) || $format == 'dt' ? $dtformat : ($format == 'd' ? $dformat : ($format == 't' ? $tformat : $format));
        if($format == 'u') {
            $todaytimestamp = TIMESTAMP - (TIMESTAMP + $timeoffset * 3600) % 86400 + $timeoffset * 3600;
            $s = gmdate(!$uformat ? $dtformat : $uformat, $timestamp);
            $time = TIMESTAMP + $timeoffset * 3600 - $timestamp;
            if($timestamp >= $todaytimestamp) {
                if($time > 3600) {
                    $return = intval($time / 3600).' '.$lang['hour'].$lang['before'];
                } elseif($time > 1800) {
                    $return = $lang['half'].$lang['hour'].$lang['before'];
                } elseif($time > 60) {
                    $return = intval($time / 60).' '.$lang['min'].$lang['before'];
                } elseif($time > 0) {
                    $return = $time.' '.$lang['sec'].$lang['before'];
                } elseif($time == 0) {
                    $return = $lang['now'];
                } else {
                    $return = $s;
                }
                if($time >=0 && !defined('IN_MOBILE')) {
                    $return = '<span title="'.$s.'">'.$return.'</span>';
                }
            } elseif(($days = intval(($todaytimestamp - $timestamp) / 86400)) >= 0 && $days < 7) {
                if($days == 0) {
                    $return = $lang['yday'].'&nbsp;'.gmdate($tformat, $timestamp);
                } elseif($days == 1) {
                    $return = $lang['byday'].'&nbsp;'.gmdate($tformat, $timestamp);
                } else {
                    $return = ($days + 1).'&nbsp;'.$lang['day'].$lang['before'];
                }
                if(!defined('IN_MOBILE')) {
                    $return = '<span title="'.$s.'">'.$return.'</span>';
                }
            } else {
                $return = $s;
            }
            return $return;
        } else {
            return gmdate($format, $timestamp);
        }
    }

    时间处理函数,在function下,很多地方都可以调用。

  • 相关阅读:
    Alink漫谈(五) : 迭代计算和Superstep
    Alink漫谈(四) : 模型的来龙去脉
    Elasticsearch索引模板-转载
    Filebeat配置文件解析-转载
    Logtash 配置文件解析-转载
    Logtash遇到的异常和注意点
    Linux中Sshd服务配置文件优化版本(/etc/ssh/sshd_config)
    运维应急方案撰写-草稿版分享
    du和df的统计结果为什么会不一样?
    全网最详细的Linux命令系列-Screen远程会话命令
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/3644652.html
Copyright © 2020-2023  润新知