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