formatting
Date.prototype.toLocaleString
Returns date and time together formatted for a given locale. Accepts the union of date and time options from Intl.DateTimeFormat.
date.toLocaleString([locales[, options]]) Parameters
| Parameter | Purpose |
|---|---|
| locales | BCP 47 tag(s) |
| dateStyle + timeStyle | shorthand for common combinations |
| timeZone | IANA zone; strongly recommended |
| timeZoneName | 'short' | 'long' | 'shortOffset' | 'longOffset' |
Examples
console.log(new Date('2026-07-19T15:30:00Z').toLocaleString('en-US', {timeZone:'UTC'})); // '7/19/2026, 3:30:00 PM' US default
console.log(new Date('2026-07-19T15:30:00Z').toLocaleString('en-US', {dateStyle:'medium', timeStyle:'short', timeZone:'America/New_York'})); // 'Jul 19, 2026, 11:30 AM' styled + zone
console.log(new Date('2026-07-19T15:30:00Z').toLocaleString('en-US', {timeZone:'UTC', timeZoneName:'short'})); // '... UTC' with zone label
Gotcha
You cannot mix dateStyle/timeStyle with individual fields like year/month - it throws TypeError. Choose one style or the other.
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.toLocaleTimeString
Returns the time portion formatted for a given locale and options, without the date. Same locale/options rules as toLocaleDateString.
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.