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'].' '.gmdate($tformat, $timestamp); } elseif($days == 1) { $return = $lang['byday'].' '.gmdate($tformat, $timestamp); } else { $return = ($days + 1).' '.$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下,很多地方都可以调用。