formatting
Date.prototype.toLocaleTimeString
Returns the time portion formatted for a given locale and options, without the date. Same locale/options rules as toLocaleDateString.
date.toLocaleTimeString([locales[, options]]) Parameters
| Parameter | Purpose |
|---|---|
| locales | BCP 47 tag(s) |
| timeStyle | 'full' | 'long' | 'medium' | 'short' |
| hour12 | true = 12-hour clock; false = 24-hour |
| timeZone | IANA zone name |
Examples
console.log(new Date('2026-07-19T15:30:00Z').toLocaleTimeString('en-US', {timeZone:'UTC'})); // '3:30:00 PM' US default 12h
console.log(new Date('2026-07-19T15:30:00Z').toLocaleTimeString('en-GB', {timeZone:'UTC', hour12:false})); // '15:30:00' UK 24h
console.log(new Date('2026-07-19T15:30:00Z').toLocaleTimeString('en-US', {timeStyle:'short', timeZone:'UTC'})); // '3:30 PM' short style
Gotcha
Without an explicit timeZone option, output depends on the host machine's zone - CI and browsers can disagree. Pass timeZone for reproducible output.
Related
Date.prototype.toLocaleDateString
Returns the date portion formatted for a given locale and options, without the time. For repeated formatting, cache an Intl.DateTimeFormat instead - it is significantly faster.
Date.prototype.toLocaleString
Returns date and time together formatted for a given locale. Accepts the union of date and time options from Intl.DateTimeFormat.
Intl.DateTimeFormat
The modern locale-aware date/time formatter, preferred over toLocaleString for repeated formatting because you can construct the formatter once and reuse it. Also offers formatToParts, formatRange, and formatRangeToParts for finer control and internationalized date ranges.
Date.prototype.toISOString
Returns the date as an ISO 8601 extended-format string in UTC, always ending in 'Z'. This is the canonical machine-readable serialization and the format most APIs and databases accept.
Date.prototype.toJSON
Returns an ISO 8601 UTC string suitable for JSON serialization; called automatically by JSON.stringify when it encounters a Date. Equivalent to toISOString() for valid dates, but returns null for Invalid Dates instead of throwing.