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