N
N
newaitix2018-03-01 18:09:15
JavaScript
newaitix, 2018-03-01 18:09:15

Pure mathematics. How to get seconds, minutes, hours from milliseconds?

html5 video player. I want to display seconds minutes and hours

video.duration // общая длительность ролика в миллисекундах
video.currentTime // текущее время ролика в миллисекундах

how all this (well, of course, I understand that something needs to be divided into something) that I can’t figure out how to what and to what. Help me please ))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Tsvetkov, 2018-03-01
@newaitix

Something like this

function time2str(time) {
    if(!time || typeof time != "number" || time < 0) {
        return "00:00:00";
    }
    var m = new Date(time * 1000).toISOString().match(/\d\d:\d\d:\d\d/);
    return m ? m[0].split(":").slice(0, 3).join(":") : "00:00:00";
}

To display the remaining time time2str(video.duration - video.currentTime)

D
Dmitry, 2018-03-01
@demon416nds

divide and take the remainder starting with a larger value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question