Last active
February 1, 2019 07:40
-
-
Save elitan/26f1feaab4bee965fcf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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