传入时间,显示多少秒之前,多少小时前发布
function user_beforeTime($givenTime) {
$givenDateTime = new DateTime($givenTime);
$currentTime = new DateTime();
$timeDiff = $givenDateTime->diff($currentTime);
$hoursDiff = $timeDiff->h;
$minutesDiff = $timeDiff->i;
$secondsDiff = $timeDiff->s; // 添加秒差
if ($hoursDiff > 0) {
return $hoursDiff . "小时前";
} elseif ($minutesDiff > 0) {
if ($secondsDiff > 0) {
return $minutesDiff . "分钟前";
} else {
return $minutesDiff . "分钟前";
}
} elseif ($secondsDiff > 0) { // 如果时间在一分钟内
return $secondsDiff . "前";
} else {
return $givenTime;
}
}
栏目页面,调用当前栏目总数
function user_ListNum($classArray){
global $empire,$dbtbpre,$class_r;
$num = 0;
$classid = $classArray['classid'];
if($classArray['bclassid']==0 && $classArray['islast']==0){
$sql=$empire->query("SELECT classid,allinfos FROM `{$dbtbpre}enewsclass` WHERE bclassid={$classid};");
while($r=$empire->fetch($sql))
{
$num += $r['allinfos'];
}
}else{
$r=$empire->fetch1("select classid,allinfos from {$dbtbpre}enewsclass where classid={$classid}");
$num = $r['allinfos'];
}
return $num;
}
发表评论