Created
July 11, 2021 14:55
-
-
Save camilamoreiradev/ae0446c5aa8f7be301a618226af0fd23 to your computer and use it in GitHub Desktop.
Function for converting seconds into hours.
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
function convertSecondsForHours($seconds) { | |
$second = $seconds % 60; | |
$minutes = floor($seconds / 60); | |
$minute = $minutes % 60; | |
$hour = floor($minutes / 60); | |
return str_pad($hour, 2,0, STR_PAD_LEFT) . ":" . str_pad($minute, 2,0, STR_PAD_LEFT) . ":" . str_pad($second, 2,0, STR_PAD_LEFT); | |
} | |
$seconds = '14993'; | |
$hour = convertSecondsForHours($seconds); | |
/* | |
The return is 04:09:53 hours. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment