Skip to content

Function.formatDateTime

connor-baer edited this page Oct 11, 2024 · 35 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