-
-
Save parzibyte/ae24fb5110959528151f3307c71a8a7c 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
const obtenerNumeroAleatorioEnRango = (min, max) => { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
const fechaAleatoria = () => { | |
const fecha = new Date(obtenerNumeroAleatorioEnRango(2020, 2021), obtenerNumeroAleatorioEnRango(0, 11), obtenerNumeroAleatorioEnRango(1, 28), obtenerNumeroAleatorioEnRango(0, 23), obtenerNumeroAleatorioEnRango(0, 59), obtenerNumeroAleatorioEnRango(0, 59)); | |
return fecha; | |
} | |
const obtenerCadenaFecha = (fecha) => { | |
const mes = fecha.getMonth() + 1; // Ya que los meses los cuenta desde el 0 | |
const dia = fecha.getDate(); | |
const cadenaFecha = `${fecha.getFullYear()}-${agregarCeroSiEsNecesario(mes)}-${agregarCeroSiEsNecesario(dia)}`; | |
const cadenaHora = `${agregarCeroSiEsNecesario(fecha.getHours())}:${agregarCeroSiEsNecesario(fecha.getMinutes())}:${agregarCeroSiEsNecesario(fecha.getSeconds())}`; | |
return cadenaFecha + "T" + cadenaHora; | |
} | |
const agregarCeroSiEsNecesario = (valor) => { | |
if (valor < 10) { | |
return '0'.concat(valor); | |
} | |
return valor.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment