formatTime
Calendar
stable
Format a Date object as a locale-aware time string in 12-hour or 24-hour notation, using Intl.DateTimeFormat so the locale separator and AM/PM marker are honoured.
API
Signature
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- daterequiredDate
- The Date object whose time portion will be formatted.
- formatrequired'12h' | '24h'
- Clock format: '12h' for AM/PM notation, '24h' for 24-hour notation.
- localestring
- Optional BCP 47 locale tag (e.g. 'en-US'). Falls back to the runtime default when omitted.
API
Return value
The value returned by this util.
- Locale-formatted time string, e.g. "02:05 PM" or "14:05".
Usage
Examples
Ready-to-paste usage snippets.
Format time in 12h and 24h