JavaScript Reference ยท Date and Intl
Date.prototype.toString() and friends
Reference for the JavaScript Date string methods: toString, toDateString, toTimeString, toUTCString, toLocaleString and toJSON, and which to use when.
Besides toISOString() and the toLocale...String() methods, Date has several other ways to turn a date into text. They differ in which time zone they use, which parts they include, and whether the format is meant for machines or people.
toString() is the one JavaScript calls for you: String(date), template literals and string concatenation all use it. Its output depends on the time zone of the device, so it is good for debugging and bad for data.
const d = new Date(Date.UTC(2026, 2, 15, 9, 30)); d.toUTCString(); // "Sun, 15 Mar 2026 09:30:00 GMT"
Try it
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Syntax
date.toString() date.toDateString() date.toTimeString() date.toUTCString() date.toLocaleString(locales, options) date.toJSON()
| Method | Result (example) |
|---|---|
toString() |
"Sun Mar 15 2026 09:30:45 GMT+0100 (Central European Standard Time)" โ local date, time, offset and zone name |
toDateString() |
"Sun Mar 15 2026" โ the local date only |
toTimeString() |
"09:30:45 GMT+0100 (Central European Standard Time)" โ the local time and zone only |
toUTCString() |
"Sun, 15 Mar 2026 08:30:45 GMT" โ RFC 7231 style, as used in HTTP headers |
toLocaleString() |
date and time in the user's locale, for example "3/15/2026, 9:30:45 AM" |
toJSON() |
the same as toISOString(), or null for an invalid date |
Parameters: none, except toLocaleString(), which takes the same locales and options as toLocaleDateString().
Return value: a string. An invalid date gives "Invalid Date" from all of them except toJSON() (null) and toISOString() (which throws).
Usage notes
toString()depends on the device. The offset and zone name change between computers, and zone names are even translated on some systems. Do not store or compare it.toUTCString()is stable and ends inGMT. Use it for HTTP headers such asExpires, and for cookie expiry dates.toGMTString()is an old alias oftoUTCString(); do not use it.- Implicit conversion is the odd one out. For most objects
+prefers numbers, but aDateprefers a string. Sodate + 1concatenates text, whiledate - 1calculates with the timestamp. - Templates and
String(date)calltoString(). Spell out the method if you want something else. - JSON always uses the ISO format through
toJSON(). toLocaleString()includes both date and time and is meant for people. For the best control over the output, useIntl.DateTimeFormat.- A fixed local format is easiest to build from the getters when you need exact output such as
2026-03-15 09:30.
Browser support
All of these methods work in every browser and runtime. The exact wording of toString() can differ slightly between engines.