-
-
Save parzibyte/be206fad35daaa858adcb210fa4c6b07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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