PHP函数处理
/*格式化时间戳为小时,分钟,秒,几天前等*/
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 = ‘‘.$return.‘‘; } } 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 = ‘‘.$return.‘‘; } } else { $return = $s; } return $return; } else { return gmdate($format, $timestamp); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。