formatting
Date.prototype.toString
Returns a fixed English representation of the date in LOCAL time, e.g. 'Sun Jul 19 2026 05:30:00 GMT+0530 (India Standard Time)'. Called implicitly by template literals and string concatenation.
date.toString() Parameters
| Parameter | Purpose |
|---|---|
| () | no arguments; English + local zone |
| implicit | used by `${date}` and String(date) |
| Invalid Date | returns the literal string 'Invalid Date' |
Examples
console.log(String(new Date('2026-07-19T00:00:00Z'))); // e.g. 'Sun Jul 19 2026 ...' implicit conversion
console.log(new Date('bad').toString()); // 'Invalid Date' no throw, string sentinel
console.log(`Now: ${new Date()}`); // uses toString template literal
Gotcha
Format is engine-specified English and varies slightly between browsers - never parse it. For serialization use toISOString; for display use Intl.DateTimeFormat.
Related
Date.prototype.toDateString
Returns the date portion of the Date as a fixed English string, e.g. 'Sun Jul 19 2026'. Companion to toTimeString which returns something like '15:30:00 GMT+0530 (India Standard Time)'.
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.
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.