今天写一个东西的时候 发现给出的是秒数。实在找不到直接的工具去转换。

就去网上找了个转换方法(有现成的就不写了,以后再简化下代码)。 

 function formatSeconds(value) {
            var theTime = parseInt(value);//
            var theTime1 = 0;//
            var theTime2 = 0;// 小时
            // alert(theTime);
            if(theTime > 60) {
                theTime1 = parseInt(theTime/60);
                theTime = parseInt(theTime%60);
                // alert(theTime1+"-"+theTime);
                if(theTime1 > 60) {
                    theTime2 = parseInt(theTime1/60);
                    theTime1 = parseInt(theTime1%60);
                }
            }
            var result = ""+parseInt(theTime)+"秒";
            if(theTime1 > 0) {
                result = ""+parseInt(theTime1)+"分"+result;
            }
            if(theTime2 > 0) {
                result = ""+parseInt(theTime2)+"小时"+result;
            }
            return result;
        }

 

相关文章:

  • 2022-02-07
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-26
  • 2021-10-02
  • 2022-12-23
猜你喜欢
  • 2021-09-28
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2021-12-14
  • 2022-12-23
相关资源
相似解决方案