Reputation: 961
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
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