chris-ELM
4/6/2014 - 1:10 PM

String to time From https://news.layervault.com/stories/19629-favorite-code-snippets

/* Converts String number of seconds into  00:00 formatted time */
String.prototype.toTime = function () {
    var secNum = parseInt(this, 10); 
    var hours   = Math.floor(secNum / 3600);
    var minutes = Math.floor((secNum - (hours * 3600)) / 60);
    var seconds = secNum - (hours * 3600) - (minutes * 60);

    if (hours   < 10) {hours   = "0"+hours;}
    if (minutes < 10) {minutes = "0"+minutes;}
    if (seconds < 10) {seconds = "0"+seconds;}
    var time    = minutes+':'+seconds;
    return time;