-
Notifications
You must be signed in to change notification settings - Fork 4
Function.formatDate
kodiakhq[bot] edited this page Dec 1, 2024
·
56 revisions
@sumup-oss/intl / formatDate
formatDate(
date
,locales
?,dateStyle
?):string
Formats a Date
with support for various
date styles.
Parameter | Type | Default value |
---|---|---|
date |
FormattableDate |
undefined |
locales ? |
string | string [] |
undefined |
dateStyle ? |
undefined | "short" | "long" | "full" | "medium"
|
'short' |
string
import { formatDate } from '@sumup-oss/intl';
const date = new Date(2000, 1, 1);
const locale = 'en-GB';
formatDate(date, locale, 'short'); // '01/02/2000'
formatDate(date, locale, 'medium'); // '1 Feb 2000'
formatDate(date, locale, 'long'); // '1 February 2000'
formatDate(date, locale, 'full'); // 'Tuesday, 1 February 2000'
In runtimes that don't support the Intl.DateTimeFormat
API, the date is
formatted using the Date.toLocale(Date|Time)String
API.
In runtimes that don't support the dateStyle
option, the styles are
approximated using fallback options.