Created
July 18, 2012 14:53
-
-
Save fvianello/3136668 to your computer and use it in GitHub Desktop.
convert seconds to human timing
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
<?php | |
function humanTiming($time) | |
{ | |
$tokens = array ( | |
86400 => 'giorno/i', | |
3600 => 'ore', | |
60 => 'minuti', | |
1 => 'secondi' | |
); | |
$string = ""; | |
foreach ($tokens as $unit => $text) { | |
// if ($time < $unit) continue; | |
$numberOfUnits = floor($time / $unit); | |
$time = $time - $unit*$numberOfUnits; | |
$string .= $numberOfUnits.' '.$text.' '; | |
} | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment