Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function timeElapsedString($ptime)
{
$etime = time() - $ptime;
if ($etime < 1)
{
return '0 seconds';
}
$a = array( 12 * 30 * 24 * 60 * 60 => 'år,år',
30 * 24 * 60 * 60 => 'månad,månader',
24 * 60 * 60 => 'dag,dagar',
60 * 60 => 'timme,timmar',
60 => 'minut,minuter',
1 => 'sekund,sekunder'
);
foreach ($a as $secs => $str)
{
$d = $etime / $secs;
if ($d >= 1)
{
$r = round($d);
$text = explode(',', $str);
return $r . ' ' . ($r > 1 ? $text[1] : $text[0]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.