$time = strtotime("2021-02-17 19:04:14");
echo ReckonTime($time);
function ReckonTime($time)
{
$NowTime = time();
if($time > $NowTime){ return false; }
$TimePoor = $NowTime - $time;
if ($TimePoor == 0) {
$str = '一眨眼之间';
} else if ($TimePoor < 60 && $TimePoor > 0) {
$str = $TimePoor . '秒之前';
} else if ($TimePoor >= 60 && $TimePoor <= 60 * 60) {
$str = floor($TimePoor / 60) . '分钟前';
} else if ($TimePoor > 60 * 60 && $TimePoor <= 3600 * 24) {
$str = floor($TimePoor / 3600) . '小时前';
} else if ($TimePoor > 3600 * 24 && $TimePoor <= 3600 * 24 * 7) {
if (floor($TimePoor / (3600 * 24)) == 1) {
$str = "昨天";
} else if (floor($TimePoor / (3600 * 24)) == 2) {
$str = "前天";
} else {
$str = floor($TimePoor / (3600 * 24)) . '天前';
}
} else if ($TimePoor > 3600 * 24 * 7) {
$str = date("Y-m-d", $time);
}
return $str;
}
6天前