<?php
echo (time_fitle('2016-08-17 17:00:00')); function time_fitle($date){
date_default_timezone_set('PRC');
//得到相差的秒
$_sec = time()-strtotime($date);
//如果超过当前时间返回false
if($_sec<0)return false;
//得到相差的分钟
$_min = floor($_sec/60);
//得到相差的小时
$_hour = floor($_sec/3600);
//得到相差的天
$_day = floor($_sec/86400);
//得到相差的周
$_week = floor($_sec/604800);
$txt = '';
if($_min < 15){
$txt = '刚刚';
}else if($_min >=15 && $_min<30){
$txt = '15分钟前';
}else if($_min >=30 && $_min<60){
$txt = '半小时前';
}else if($_hour<24){
$txt = $_hour."小时前";
}else if($_day<7){
$txt = $_day."天前";
}else if{
$txt = $_week."周前";
}
//只写到了周 其他模仿写即可
return $txt;
}
?>