0
timeAgoをタイムスタンプから返すこのPHP関数があります。 タイムスタンプがNOW よりも大きい場合PHP timeAgo戻り値タイムスタンプが未来の場合はX日以内
function time_ago($time) {
$periods = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
$lengths = array('60', '60', '24', '7', '4.35', '12', '10');
$now = time();
$difference = $now - $time;
for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if ($difference != 1) {
$periods[$j] .= 's';
}
return $difference . ' ' . $periods[$j] . ' ago';
}
さて、それは "47年前" を返します。 タイムスタンプがNOW よりも大きければ、それは "3日間で、5時間、16分" を返すようにする方法
?
ありがとうございました。
タイムスタンプの差が<0よりもNOWより大きい場合。 –