js converts the number of seconds to 0:00 format

Need to display the current playing time when making a music player

Such as 89 seconds, it is displayed as 1:29

Mainly use the following methods to achieve conversion:

//Convert the number of seconds to hour, minute, and second format

function formatSeconds(value) {

    var theTime = parseInt(value);// 秒

    var middle= 0;// 分

    var hour = 0;// hour

 

    if(theTime > 60) {

        middle= parseInt(theTime/60);

        theTime = parseInt(theTime%60);

        if(middle> 60) {

            hour= parseInt(middle/60);

            middle= parseInt(middle%60);

        }

    }

  var result = ''

if(parseInt(theTime)>=10){

result = "0"+":"+parseInt(theTime);

}else{

result = "0"+":"+"0"+parseInt(theTime);

}

    if(middle >= 0 && parseInt(theTime)>=10) {

        result = parseInt(middle)+":"+parseInt(theTime);

    }else{

    result = parseInt(middle)+":"+"0"+parseInt(theTime);

}

    /* if(hour> 0) {

        result = ""+parseInt(hour)+":"+result;

    } */

    return result;

}

The original text comes from here, his format is 1 minute 29 seconds  

https://blog.csdn.net/qq_22158021/article/details/81700871

Guess you like

Origin blog.csdn.net/qq_36818077/article/details/99680805