本文实例讲述了PHP实现求相对时间函数。分享给大家供大家参考。具体实现方法如下:
PHP;">
$now) $relative = 'in the future';
else {
$diff = $now - $time;
if ($diff >= $limit) $relative = date($format,$time);
elseif ($diff < 60) {
$relative = 'less than one minute ago';
} elseif (($minutes = ceil($diff / 60)) < 60) {
$relative = $minutes . ' minute' . (((int)$minutes === 1) ? '' : 's') . ' ago';
} else {
$hours = ceil($diff / 3600);
$relative = 'about ' . $hours . ' hour' . (((int)$hours === 1) ? '' : 's') . ' ago';
}
}
return $relative;
}
希望本文所述对大家的PHP程序设计有所帮助。