Skip to content

Instantly share code, notes, and snippets.

@elitan
Last active February 1, 2019 07:40
Show Gist options
  • Save elitan/26f1feaab4bee965fcf0 to your computer and use it in GitHub Desktop.
Save elitan/26f1feaab4bee965fcf0 to your computer and use it in GitHub Desktop.
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