Convert hours and minutes into javascript minutes

Asked

Viewed 1,248 times

-2

I need a method that converts the time and minutes typed in < input type="time" > by user in minutes.

ex: 01:35 return 95 minutes

it is possible to perform operations with this input ?

  • What would be the date format? 5h 2min or 5:02 in input?

  • the time format typed in input type=time 5:02 and returned the value 302

  • Already answered. If it works let me know.

  • Thanks Master was exactly what I needed! : D

1 answer

2


Solution to the problem:

<!DOCTYPE html>
<html>
    <body>
        <input type="time" id="data">
        <button onclick="minutes()">Result</button>
        <p id="value"></p>
        <script>
            var data = document.getElementById("data");
            var value = document.getElementById("value");
            function minutes() {
                let f0 = data.value.split(":");
                value.innerHTML = ((Number(f0[0])*60)+Number(f0[1])) + " Minutes";
                return 0;
            }
        </script>
    </body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.