Skip to content

Instantly share code, notes, and snippets.

@deyvicode
Created January 8, 2022 13:15
Show Gist options
  • Save deyvicode/65c9e1722b94beed01517af86cdabb2d to your computer and use it in GitHub Desktop.
Save deyvicode/65c9e1722b94beed01517af86cdabb2d to your computer and use it in GitHub Desktop.
Formatear fechas con traducciones en JavaScript.
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