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

235
Vistas
How can I convert a timestamp to seconds in java script

I want to convert this:

00:07:57,685

to seconds. It should return 00*60 + 07*60 + 57,685 The problem is its format I did not manage to write an optimized function.

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

0

const input = "00:07:57,685";
const [hours, minutes, secondsRaw] = input.split(/:/g);
const seconds = secondsRaw.replace(",", ".");

let output = 0;
output += parseInt(hours) * 3600;
output += parseInt(minutes) * 60;
output += parseFloat(seconds);

console.log(`${output} seconds`);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Here is a working sample :

function stringTimeToSecond (stringTime) {
    // convert from "," float notation to "." float notation
    // split your string to [h, m, s]
    // reverse to get [s, m, h] to be able to use indice on the reduce method
    const stringTimeArray = stringTime.replace(',','.').split(":").reverse();
    // 60^0 = 1 for seconds
    // 60^1 = 60 for minutes
    // 60^2 = 3600 for hours
    return stringTimeArray.reduce((timeInSecond, time, i) => {
         timeInSecond += time * Math.pow(60, i);
         return timeInSecond;
    }, 0);
}

Reduce method will iterate through your array and then return your accumulator "timeInSecond". The accumulator is initialized to 0 as the second argument of the reduce function.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I think this might work if i understood your question right:

let timestamp = "00:07:57,685"
let seconds = timestamp.split(":")[2].split(",")[0]
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