Last active
December 16, 2021 16:55
-
-
Save olegchursin/2b9d0718f3c1a5012335ac2a50326758 to your computer and use it in GitHub Desktop.
Native Datetime Formatter
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
// define formatter | |
const locales: string | string[] = 'en-US'; | |
const options: Intl.DateTimeFormatOptions = { | |
year: 'numeric', | |
month: 'short', | |
day: 'numeric', | |
hour: 'numeric', | |
minute: '2-digit' | |
}; | |
const formatter: Intl.DateTimeFormat = new Intl.DateTimeFormat( | |
locales, | |
options | |
); | |
// use | |
const date = new Date(); | |
const formattedDate = formatter.format(date); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment