'How to convert minutes and seconds of audio/video to currentTime in javascript?

I have the string of video time is "02:30" and video.duration of video is 239. Now, how to convert "02:30" to currentTime?



Solution 1:[1]

Use split(":") can solve that, i hope below will help you:

function convert(str){
  let a = str.split(':')
  return Number(a[0]) * 60 + Number(a[1])
}
const currentTime = convert('02:30')
console.log("currentTime is", currentTime)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1