Created
December 7, 2018 04:33
-
-
Save webinista/6436e851a02f0338cb86530e6e9ae2bf to your computer and use it in GitHub Desktop.
Make YouTube API duration readable using PHP
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
/* | |
PHP function for converting an ISO8601 duration (the kind used by YouTube's API) | |
to something more readable. | |
*/ | |
make_readable_duration($duration) | |
{ | |
$duration = new DateInterval($duration); | |
return $duration->format('%H:%I:%S'); | |
} | |
print make_readable_duration('PT2M16S'); // Prints 00:02:16 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment