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
Signature TypeScript complète, extraite du fichier util.
API
Paramètres
Paramètres d'entrée acceptés par cet util.
- daterequisDate
- The Date object whose time portion will be formatted.
- formatrequis'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
Valeur de retour
La valeur retournée par cet util.
- Locale-formatted time string, e.g. "02:05 PM" or "14:05".
Usage
Exemples
Extraits de code prêts à coller.
Format time in 12h and 24h