Skip to content

Instantly share code, notes, and snippets.

@webinista
Created December 7, 2018 04:33
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 webinista/6436e851a02f0338cb86530e6e9ae2bf to your computer and use it in GitHub Desktop.
Save webinista/6436e851a02f0338cb86530e6e9ae2bf to your computer and use it in GitHub Desktop.
Make YouTube API duration readable using PHP
/*
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