/ Published in: JavaScript
Convert number of seconds to HH:MM
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function secsTime(inSecs) { var timeStr = new String(); var seconds = parseInt(inSecs); if (seconds < 0) { timeStr = "-"; seconds *= -1; } var hours = parseInt(seconds/3600); var minutes = parseInt((seconds - (hours * 3600))/60); if (hours < 10) { if (hours == 0) { timeStr += "00:"; } else { timeStr += "0" + hours + ":"; } } else { timeStr += hours + ":"; } if (minutes < 10) { if (minutes == 0) { timeStr += "00"; } else { timeStr += "0" + minutes; } } else { timeStr += minutes; } return timeStr; };