php计算时分秒,非常好用,进来!!!//第一个,当您执行一件事,用了多长时间,计算开始到结束的时间差
//$begin_time开始时间 $end_time 结束时间
//最后得出 xx时xx分xx秒
function get_timediff($begin_time,$end_time)
{
if($begin_time
$starttime = $begin_time;
$endtime = $end_time;
}else{
$starttime = $end_time;
$endtime = $begin_time;
}
//计算天数
$timediff = $endtime-$starttime;
$days = intval($timediff/86400);
//计算小时数
$remain = $timediff%86400;
$hours = intval($remain/3600);
//计算分钟数
$remain = $remain%3600;
$mins = intval($remain/60);
//计算秒数
$secs = $remain%60;
//$res = array("day" => $days,"hour" => $hours,"min" => $mins,"sec" => $secs);
return "{$hours}时{$mins}分{$secs}秒";
}
//第二个,当你发表了一个文章,计算多少分秒之前
//$time 时间戳
//最后得出 xx秒前
function get_timejq($time){
//计算天数
$timediff = time()-$time;
$days = intval($timediff/86400);
if($days!=0){
return $days."天前";
}
//计算小时数
$remain = $timediff%86400;
$hours = intval($remain/3600);
if($hours!=0){
return $hours."小时前";
}
//计算分钟数
$remain = $remain%3600;
$mins = intval($remain/60);
if($mins!=0){
return $mins."分钟前";
}
//计算秒数
$secs = $remain%60;
return $secs."秒前";
}
$time = time()-60*60*25;
echo get_timejq($time);
//输出1天前
更多请加QQ群324098841
论坛 http://bbs.flash127.com
AD:真正免费,域名+虚机+企业邮箱=0元