将分-秒百分之一(00:00:00)转换为秒

Convert minutes seconds hundredths (00:00:00) to seconds?

本文关键字:转换 -秒 将分 百分之一      更新时间:2023-09-26

是否可以将分秒00:00:00转换为秒。10:00:00变成600秒?这是我的

    function time(){
       var time = document.getElementById("timeEntered").value;
       var a = time.split(":");
       var timeToSeconds = (+a[0]) * 60 + (+a[1]) * 60 + (+a[2]);
    }
    <body>
       <div>
          <input type="text" id="timeEntered">&nbsp;&nbsp;
       </div>
    </body>

如果你不需要第100个,你可以这样做:

var timeToSeconds = 60*a[0]+a[1];

如果你想有秒作为浮动,它将是这样的:

var timeToSeconds = 60*a[0]+a[1]+0.01*a[2];

最后,也许你想把第100个:四舍五入

var timeToSeconds = 60*a[0]+a[1]+Math.round(0.01*a[2]);