I would like some help converting seconds into a MM:DD:HH:MM:SS format.
I have this code here:
<?php
// Convert seconds into months, days, hours, minutes, and seconds.
function secondsToTime($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";
}
?>
It outputs an example of
0 months, 1 days, 3 hours, 46 minutes, 39 seconds
I would just like it to be something like
00:01:03:46:39
How can I do that?
From what I gather, it looks like you’re interested in returning a string with values containing two digits separaed by colons. Assuming the positioning doesn’t need to change, you can do something similar to the following:
Or if you don’t like the thought of having one more function to manage, perhaps this may suit you better:
And then to call our function (whichever method you decide to use):