Wednesday, February 27, 2008

A JavaScript Function to convert Number of Seconds to hh:mm:ss format.

function ConvertToHoursAndMinutes(seconds)

{

var intFHours = 0;

var intFMin = 0;

var intFSec = 0;

intFHours = parseInt(parseInt(seconds) / 3600);

intFMin = parseInt(parseInt(parseInt(seconds) % 3600) / 60);

intFSec = parseInt(parseInt(parseInt(seconds) % 3600) % 60);

var strHours = PadZeroBefore(intFHours);

var strMins = PadZeroBefore(intFMin);

var strSecs = PadZeroBefore(intFSec);

var strReturn = strHours + ":" + strMins + ":" + strSecs;

return strReturn;

}

function PadZeroBefore(number)

{

var s = number + "";

if(s.length <>

{s="0"+s;}

return s;

}

No comments: