3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function time_format($time) { $a = array( 12 * 30 * 24 * 60 * 60 => 'year', 30 * 24 * 60 * 60 => 'month', 24 * 60 * 60 => 'day', 60 * 60 => 'hour', 60 => 'minute', 1 => 'second' ); foreach ($a as $secs => $str) { $d = $time / $secs; if ($d >= 1) { $r = round($d); return $r . ' ' . $str . ($r > 1 ? 's' : ''); } } return 0; } echo time_format(59013);
Output for 4.3.0 - 5.6.21, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
16 hours