PHP实现几秒前、几分钟前、几小时前、几天前
/** * @Description: * @Author: Yang * @param $the_time 需要转换的时间 * @return string */ function time_tran($the_time) { $show_time = strtotime($the_time); $dur = time() - $show_time; if ($dur < 0) { return $the_time; } else { if ($dur < 60) { return $dur . '秒前'; } else { if ($dur < 3600) { return floor($dur / 60) . '分钟前'; } else { if ($dur < 86400) { return floor($dur / 3600) . '小时前'; } else { if ($dur < 259200) { // 3天内 return floor($dur / 86400) . '天前'; } else { return $the_time; } } } } } }

浙公网安备 33010602011771号