Created
May 13, 2013 15:24
-
-
Save jgornick/5569137 to your computer and use it in GitHub Desktop.
PHP: Convert seconds to hours:minutes:seconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$diff = 450752; | |
$format = sprintf('%02d:%02d:%02d', ($diff / 3600), ($diff / 60 % 60), $diff % 60); | |
echo $format; |
why not
gmdate('H:i:s', $seconds)
Cose it works only to 24h?
sprintf('%02d',floor($seconds / 3600)).gmdate(":i:s", $seconds % 3600);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$h_ = (($diff / 3600) >= 1) ? '%02d:':'';
$m_ = (($diff / 60 % 60) >= 1) ? '%02d:':'';
$format = sprintf($h_.$m_.'%02d', ($diff / 3600), ($diff / 60 % 60), $diff % 60);
return $format;
if hour or minute = 0 not need show 00.