I am using gmdate
in PHP to convert seconds to H:i:s
I have this code:
echo gmdate("H:i:s", '480002');
So i should be converting 480002 seconds to H:i:s which should show
133:20:02
but its only showing
13:20:02
I am using gmdate
in PHP to convert seconds to H:i:s
I have this code:
echo gmdate("H:i:s", '480002');
So i should be converting 480002 seconds to H:i:s which should show
133:20:02
but its only showing
13:20:02
Use this
<?php
$init = 480002;
$hours = floor($init / 3600);
$minutes = floor(($init / 60) % 60);
$seconds = $init % 60;
echo "$hours:$minutes:$seconds";
?>
gmdate is working with date values not dateinterval values, H in the format string therefore represents the number of hours since midnight. Generally days don't have 133 hours, so this is interpreted as 5 days and 13 hours. You haven't asked it to display the days part, so it just shows 13 hours.
There are various ways to calculate the total number of hours.
I'd suggest looking at this question: Calculate number of hours between 2 dates in PHP