Created
August 18, 2016 19:11
-
-
Save aramboyajyan/76fb4e6540511abfd83cf87ea9633f92 to your computer and use it in GitHub Desktop.
Format number of seconds to HH:MM:SS.
This file contains 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 format_duration($seconds) { | |
$time = round($seconds); | |
// Check if video length is longer than 1 hour. If not, we will skip the hour | |
// numbers. | |
if ($seconds > 60 * 60) { | |
$formatted = sprintf('%02d:%02d:%02d', ($time / 3600), ($time / 60 % 60), $time % 60); | |
} | |
else { | |
$formatted = sprintf('%02d:%02d', ($time / 60 % 60), $time % 60); | |
} | |
return $formatted; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment