Function.formatDate - sumup-oss/intl-js GitHub Wiki
@sumup-oss/intl / formatDate
Function: formatDate()
formatDate(
date
,locales
?,dateStyle
?):string
Formats a Date
with support for various
date styles.
Parameters
Parameter | Type | Default value |
---|---|---|
date |
FormattableDate |
undefined |
locales ? |
string | string [] |
undefined |
dateStyle ? |
undefined | "short" | "long" | "full" | "medium" |
'short' |
Returns
string
Example
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'
Remarks
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.