-1

Is it possible to convert minutes seconds hundredths 00:00:00 to seconds. 10:00:00 becomes 600 secs? This is a general idea what I have

    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>
user5544269
  • 21
  • 1
  • 3

1 Answers1

0

If you don't need 100th you can do it like that:

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

if you want to have seconds as float, it will be this way:

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

finally, maybe you'd like to round up the 100th:

var timeToSeconds = 60*a[0]+a[1]+Math.round(0.01*a[2]);
onerror
  • 606
  • 5
  • 20