Skip to content
Advertisement

vanilla js – How would i display a video.currentTime value in a minutes:seconds

I’m trying to get my website to return its video.currentTime value in a minutes:seconds way

For example, this is what I need: 00:10

But I am getting: 10.04

Code:

video.ontimeupdate = () => { 
duration.textContent = video.currentTime
}

Advertisement

Answer

video.currentTime outputs the video time in seconds.

You can just convert it to minutes and seconds.

let time = video.currentTime;
let minutes = Math.floor(time / 60);
let seconds = Math.floor(time - minutes * 60);
let timeString = `${minutes}:${seconds}`;
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement