분 단위 만 인쇄하도록이 기능을 어떻게 변경할 수 있습니까?일,시, 분, 초로 시간 소인
내 말입니다 :
지금 당장
This was 7 second ago
-- Couple minutes later --
This was 5 minute 8 second ago
입니다하지만 난이 원하는 : 그 복수의 경우에도
This was 7 second ago
-- Couple minutes later --
This was 5 minute ago (i dont care about the seconds)
어떻게 확인할 수 있을까? 그러면 광고 단위 뒤에 S가 표시됩니까?
기능 :
function humanTiming($time)
{
$time = time() - $time; // to get the time since that moment
$tokens = array (
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
$result = '';
$counter = 1;
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
if ($counter > 2) break;
$numberOfUnits = floor($time/$unit);
$result .= "$numberOfUnits $text ";
$time -= $numberOfUnits * $unit;
++$counter;
}
return "This was {$result} ago";
}