user3003810
user3003810

Reputation: 961

get youtube video duration in specific format

I'm using youtube version 3 api to get video data, I got the duration of video in ISO 8601 format, I tried to convert it to HH:MM:II using the following code

<?php
$duration = 'PT3M42S';

$time = strtotime($duration);

$durationConverted = time('HH : MM : II', $duration);
echo $durationConverted;

?>

but the result = 1431647650 , I want PT3M42S converted to something like this 00:03:42 or 03:42

Upvotes: 2

Views: 2428

Answers (1)

Matt
Matt

Reputation: 116

$duration = new DateInterval('PT3M42S');
echo $duration->format('%H:%I:%S');

00:03:42

http://php.net/manual/en/class.dateinterval.php

Upvotes: 10

Related Questions