Variable.formatDateTime - sumup-oss/intl-js GitHub Wiki
@sumup-oss/intl / formatDateTime
Variable: formatDateTime()
constformatDateTime: (date,locales?,options?) =>string
Defined in: lib/date-time-format/index.ts:65
Formats a datetime 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 Temporal.PlainDate(2000, 2, 1), 'de-DE'); // '1.2.2000'
formatDateTime(new Temporal.PlainDate(2000, 2, 1), ['ban', 'id']); // '1/2/2000'
formatDateTime(new Temporal.PlainDate(2000, 2, 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 datetime 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.