Last active
January 13, 2024 20:47
-
-
Save LuisCardenasSolis/f067e73d35dc9d23544ab1aebf125c4f to your computer and use it in GitHub Desktop.
Manejo de fechas con vanilla JS
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
//Fecha actual | |
const date = new Date() | |
//Fecha menos X dias - ejm 1 | |
const day_past = new Date(new Date().getTime() - 1*86400000) | |
//Formato de fechas: | |
const day = '0'.concat(date.getDate()).slice(-2) // dd | |
const month = '0'.concat(date.getMonth() + 1).slice(-2) // mm | |
const year = date.getFullYear() // yyyy | |
const hours = '0'.concat(date.getHours()).slice(-2) | |
const minutes = '0'.concat(date.getMinutes()).slice(-2) | |
const hours12 = '0'.concat(hours % 12 || 12).slice(-2) | |
const period = hours < 12 ? 'AM' : 'PM' | |
// return `${hours}:${minutes} ${day}/${month}/${year}` | |
// return `${day}/${month}/${year} (${hours12}:${minutes} ${period})` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment