Parse YouTube Time Code PHP
I am sharing my PHP code to parse YouTube time.
<?php
function covtime($youtube_time)
{
$start = new DateTime('@0'); // Unix epoch
$start->add(new DateInterval($youtube_time));
return $start->format('g:i:s');
}
echo date("H:i:s");
echo "<br>";
echo covtime('PT2H34M25S'); // => 2:34:25
echo "<br>";
echo date("H:i:s");
echo "<br>";
preg_match_all('/(\d+)/', "PT2H34M25S", $parts);
echo "<br>";
echo date("H:i:s");
echo "<pre>";
print_r($parts);
?>