-5

Convert video time

  $json_array = file_get_contents("https://graph.facebook.com/v2.12/$PID[$FID]/videos?fields=title,length,from,description,created_time,source&limit=10&access_token=");
   $json_data=json_decode($json_array,true);

foreach($json_data['data'] as $links){

 $video_time  = $links['length'];

238.142 this time to convert 3.57

CBroe
  • 91,630
  • 14
  • 92
  • 150
Fxc Jahid
  • 9
  • 2

3 Answers3

0

Here is the algorithm:

.142 is irrelevant as you only seem to want minutes and seconds

To calculate the seconds, calculate the modulo by 60

238 % 60 = 58

To calculate the minutes, remove the seconds from your total time and divide by 60

(238 - 58) / 60 = 3

=> 3 minutes and 58 seconds

Bentaye
  • 9,403
  • 5
  • 32
  • 45
0

For this you can simply use the gmdate() function,

echo gmdate("H:i:s", 238.142); //output: 00:03:58
echo gmdate("H.i.s", 238.142); //output: 00.03.58
echo gmdate("i.s", 238.142); //output: 03.58
Nadun Kulatunge
  • 1,567
  • 2
  • 20
  • 28
0
 function vtime($lenth){

     $seconds  = $lenth;
     $hours    = floor($seconds / 3600);
     $seconds -= $hours * 3600;
     $minutes  = floor($seconds / 60);
     $seconds -= $minutes * 60;

     if($hours == 0){ return "$minutes:$seconds"; }
      elseif($minutes == 0){ return $seconds; }
       else {      return "$hours:$minutes:$seconds"; }


 } 

echo vtime('304');
Fxc Jahid
  • 9
  • 2