0

I have a script to call Youtube video duration, but it's formatted in seconds. Now, I want to change it to minutes. How can I do it with this script?

function youtubeFeedCallback(json){
  document.write(json["data"]["duration"]);
}

var stimer = "<script src=\"http://gdata.youtube.com/feeds/api/videos/"+vidid+"?v=2&alt=jsonc&callback=youtubeFeedCallback&prettyprint=true\"><\/script>";
document.write('<div class="time">'+ stimer +'</div>');

For example:

Time duration: 300 s

After conversion: 5 min.

Thanks for your help.

dda
  • 6,030
  • 2
  • 25
  • 34
Hai Tien
  • 2,929
  • 7
  • 36
  • 55

2 Answers2

4
var min = (json["data"]["duration"] /60);
var sec = ( json["data"]["duration"] % 60);
var hour = (min / 60 ); 
min = (min % 60 );
document.write(hour + " : "+min+" : "+sec);
sourcecode
  • 1,802
  • 2
  • 15
  • 17
  • Tks for your help. But it is not formatted yet. However, your suggestion also help me to solve this by check with : http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss – Hai Tien Jun 09 '13 at 05:07
1
 document.write(json["data"]["duration"]/60);
PSR
  • 39,804
  • 41
  • 111
  • 151