Skip to content

Instantly share code, notes, and snippets.

@light9
Created September 9, 2013 12:52
Show Gist options
  • Save light9/6495175 to your computer and use it in GitHub Desktop.
Save light9/6495175 to your computer and use it in GitHub Desktop.
This is a simple PHP code that converts a number of seconds into a string according to the following format: M d h m s. Number of months is an approx calculation supposing months are 30 days long.
function seconds2human($ss) {
$s = $ss%60;
$m = floor(($ss%3600)/60);
$h = floor(($ss%86400)/3600);
$d = floor(($ss%2592000)/86400);
$M = floor($ss/2592000);
return "$M months, $d days, $h hours, $m minutes, $s seconds";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment