Skip to content

Instantly share code, notes, and snippets.

@fvianello
Created July 18, 2012 14:53
Show Gist options
  • Save fvianello/3136668 to your computer and use it in GitHub Desktop.
Save fvianello/3136668 to your computer and use it in GitHub Desktop.
convert seconds to human timing
<?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