Skip to content

Instantly share code, notes, and snippets.

@olegchursin
Last active December 16, 2021 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegchursin/2b9d0718f3c1a5012335ac2a50326758 to your computer and use it in GitHub Desktop.
Save olegchursin/2b9d0718f3c1a5012335ac2a50326758 to your computer and use it in GitHub Desktop.
Native Datetime Formatter
// 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