Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting seconds to a usable time format

Status
Not open for further replies.

junkjones

Programmer
Jul 14, 2000
52
GB
Hi all,

I am doing some work with videos right now, and I'm having trouble converting the seconds into a time format. For instance: the duration of the video returns a value of 1218.599 (seconds), but I want it to display it as 20:18. Is there a way to do this with javascript? If I just divide by sixty then I get the right amount of minutes, but the seconds are incorrect. Any help is appreciated!
 
Try:

var totalseconds=1218.599
var seconds=Math.round(totalseconds%60);
var minutes=Math.floor(totalseconds/60);
var totaltime= minutes + ':' + seconds;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top