Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

269
Vistas
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?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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)

about 4 years ago · Juan Pablo Isaza Denunciar

0

A one line solution

If you want a simple one line solution you could use Array.reduce. Note that split returns a string[2], but we convert these to numbers by applying math operators, for example +mm is shorthand for Number(mm). Also see MDN JavaScript arrow functions

let toMinutes = hhmm => hhmm.split(":").reduce((hh, mm) => +mm + 60 * hh );

Run the code snippet to view test output

let toMinutes = hhmm => hhmm.split(":").reduce((hh, mm) => +mm + 60 * hh );

// TEST

["00:30", "1:00", "01:15", "1:30", "01:45", "2:00", "2:15", "2:30", "2:45", "3:00", "24:00" ].forEach(t => {

  console.log(`${t} = ${toMinutes(t)} minutes`)
  
});

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda