Skip to content

Instantly share code, notes, and snippets.

@aramboyajyan
Created August 18, 2016 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aramboyajyan/76fb4e6540511abfd83cf87ea9633f92 to your computer and use it in GitHub Desktop.
Save aramboyajyan/76fb4e6540511abfd83cf87ea9633f92 to your computer and use it in GitHub Desktop.
Format number of seconds to HH:MM:SS.
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