Created
January 8, 2022 13:15
-
-
Save deyvicode/65c9e1722b94beed01517af86cdabb2d to your computer and use it in GitHub Desktop.
Formatear fechas con traducciones en JavaScript.
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 format = (date, locale, options) => new Intl.DateTimeFormat(locale, options).format(date) | |
const now = new Date() | |
format(now, 'es') // '8/1/2022' | |
format(now, 'es', { dateStyle: 'long' }) // '8 de enero de 2022' | |
format(now, 'es', { timeStyle: 'short' }) // '8:13' | |
format(now, 'ko') // '2022. 1. 8.' | |
format(now, 'en', { weekday: 'short', day: 'numeric' }) // '5 Wed' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment