Created
November 8, 2014 15:49
-
-
Save sionex-code/1397e286c0792a814d79 to your computer and use it in GitHub Desktop.
Youtube Accurate Duration Conversion PHP Snippet
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 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