blueCrafter6
blueCrafter6

Reputation: 469

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
}

Upvotes: 0

Views: 357

Answers (1)

Casper Kuethe
Casper Kuethe

Reputation: 1130

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}`;

Upvotes: 2

Related Questions