Skip to content

Instantly share code, notes, and snippets.

@sionex-code
Created November 8, 2014 15:49
Show Gist options
  • Save sionex-code/1397e286c0792a814d79 to your computer and use it in GitHub Desktop.
Save sionex-code/1397e286c0792a814d79 to your computer and use it in GitHub Desktop.
Youtube Accurate Duration Conversion PHP Snippet
function AccurateDuration($ytDuration) {
$di = new DateInterval($ytDuration);
// h i s
$dur = '';
if (!$di->h == 0){
if (strlen($di->h) == 1){
$dur .= '0'.$di->h.':';
}else{
$dur .= $di->h.':';
}
}
if (!$di->i == 0){
if (strlen($di->i) == 1 ){
$dur .= '0'.$di->i.':';
}else{
$dur .= $di->i.':';
}
}
if (!$di->s == 0){
if (strlen($di->s) == 1){
$dur .= '0'.$di->s;
}else{
$dur .= $di->s;
}
return $dur;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment