Function.formatDate - sumup-oss/intl-js GitHub Wiki

@sumup-oss/intl / formatDate

Function: formatDate()

formatDate(date, locales?, dateStyle?): string

Defined in: lib/date-time-format/index.ts:103

Formats a date with support for various date styles.

Parameters

Parameter Type Default value Description
date FormattableDate undefined -
locales? string | string[] undefined Formatting locale. Omitting this is deprecated and will become required in a future major version. When omitted, formatting uses the runtime default (browser or server locale), which may not match your user.
dateStyle? "full" | "long" | "medium" | "short" | undefined 'short' -

Returns

string

Example

import { formatDate } from '@sumup-oss/intl';

const date = new Temporal.PlainDate(2000, 2, 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.