Skip to content

Function.formatDateTime

kodiakhq[bot] edited this page Dec 1, 2024 · 56 revisions

@sumup-oss/intl / formatDateTime

Function: formatDateTime()

formatDateTime(date, locales?, options?): string

Formats a Date with support for various date and time styles.

Parameters

Parameter Type
date FormattableDateTime
locales? string | string[]
options? DateTimeFormatOptions

Returns

string

Example

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

formatDateTime(new Date(2000, 1, 1), 'de-DE'); // '1.2.2000'
formatDateTime(new Date(2000, 1, 1), ['ban', 'id']); // '1/2/2000'
formatDateTime(new Date(2000, 1, 1, 12, 30), 'en-GB', {
  year: 'numeric',
  month: 'short',
  day: 'numeric',
  hour: '2-digit',
  minute: '2-digit',
}); // 1 Feb 2000, 12:30

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 and timeStyle options, the styles are approximated using fallback options.

Defined in

lib/date-time-format/index.ts:60