Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active October 20, 2021 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/be206fad35daaa858adcb210fa4c6b07 to your computer and use it in GitHub Desktop.
Save parzibyte/be206fad35daaa858adcb210fa4c6b07 to your computer and use it in GitHub Desktop.
/*
https://parzibyte.me/blog
*/
const agregarCeroSiEsNecesario = valor => {
if (valor < 10) {
return "0" + valor;
} else {
return "" + valor;
}
}
const milisegundosAMinutosYSegundos = (milisegundos) => {
const minutos = parseInt(milisegundos / 1000 / 60);
milisegundos -= minutos * 60 * 1000;
const segundos = (milisegundos / 1000);
return `${agregarCeroSiEsNecesario(minutos)}:${agregarCeroSiEsNecesario(segundos.toFixed(1))}`;
};
const pruebas = [60000, 15000, 1000, 600000];
for (const prueba of pruebas) {
const conversion = milisegundosAMinutosYSegundos(prueba);
console.log("Los %d milisegundos se convierten a %s\n", prueba, conversion);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment