php code of Duration
Posted On at by milan
function duration($seconds, $max_periods)
{
$periods = array("year" => 31536000, "month" => 2419200, "week" => 604800, "day" => 86400, "hour" => 3600, "minute" => 60, "second" => 1);
$i = 1;
foreach ( $periods as $period => $period_seconds )
{
$period_duration = floor($seconds / $period_seconds);
$seconds = $seconds % $period_seconds;
if ( $period_duration == 0 )
{
continue;
}
$duration[] = "{$period_duration} {$period}" . ($period_duration > 1 ? 's' : '');
$i++;
if ( $i > $max_periods )
{
break;
}
}
return implode(' ', $duration);
}
print(duration(time(), 6) . "n");
print(duration(time(), 4) . "n");
print(duration(time(), 2) . "n");
?>
PHP Free Code