Skip to content

Instantly share code, notes, and snippets.

@camilamoreiradev
Created July 11, 2021 14:55
Show Gist options
  • Save camilamoreiradev/ae0446c5aa8f7be301a618226af0fd23 to your computer and use it in GitHub Desktop.
Save camilamoreiradev/ae0446c5aa8f7be301a618226af0fd23 to your computer and use it in GitHub Desktop.
Function for converting seconds into hours.
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