Skip to content

Instantly share code, notes, and snippets.

@sjs
Created March 2, 2015 20:17
Show Gist options
  • Save sjs/b64f6e2bdf2c88dabfbd to your computer and use it in GitHub Desktop.
Save sjs/b64f6e2bdf2c88dabfbd to your computer and use it in GitHub Desktop.
niceseconds.php
function niceseconds($ss) {
$s = $ss%60;
$m = floor(($ss%3600)/60);
$h = floor(($ss%86400)/3600);
$d = floor(($ss%2592000)/86400);
$M = floor($ss/2592000);
$response = '';
if($M != 0) { $response .= "$M months, "; }
if($d != 0) { $response .= "$d days, "; }
if($h != 0) { $response .= "$h hours, "; }
if($m != 0) { $response .= "$m minutes, "; }
if($s != 0) { $response .= "$s seconds, "; }
return rtrim($response, ', ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment