Get the current Youtube Video time using JavaScript
In this tutorial, we are going to learn about how to get the current time of a Youtube Video using JavaScript.
Getting the current time
To get the current time of a Youtube video, first we need to access that element inside the JavaScript using the document.getElementById() method.
const ytvideo = document.getElementById("video-player");Now, we need to call the getCurrentTime() method on it to get the current time.
ytvideo.getCurrentTime();Full example:
const ytvideo = document.getElementById("video-player");
ytvideo.getCurrentTime();The getCurrentTime() method returns the elapsed time in seconds since the video started playing.
Note: elapsed time means end time - start time


