formatDateTime()function
formatDateTime(date: PossibleDate, options?: DateFormatOptions, caller: AnyCaller = formatDateTime): string
| Param | Type | |
|---|---|---|
date | PossibleDate | Date to format. required |
options | DateFormatOptions | Formatting options passed through to Date.toLocaleString. |
.locale | Intl.Locale | Override the locale for formatting (defaults to detected locale). readonly |
caller | AnyCaller | Function to attribute a thrown error to (defaults to formatDateTime itself). Defaults to formatDateTime |
| Return | |
|---|---|
string | Locale-formatted datetime string. |
| Throws | |
|---|---|
RequiredError | If date cannot be converted to a valid date. |
Format a datetime in the browser locale (no seconds by default).
Examples
formatDateTime("2025-01-01T13:30") // "1/1/2025, 01:30 PM"