Date.prototype.toUTCString()
Returns the date as an RFC 7231 style UTC string, the format HTTP headers require.
toUTCString()- Added in JavaScript ES1 (1997)
Return value
stringA string representing the given date using the UTC time zone, in the format "Www, dd Mmm yyyy HH:mm:ss GMT" — three-letter weekday, two-digit zero-padded day of month, three-letter month, four-or-more-digit year, and zero-padded hours, minutes and seconds. Returns "Invalid Date" if the date is invalid.
Changelog
- PHP ES2018The format was standardized as "Www, dd Mmm yyyy HH:mm:ss GMT". Older engines emitted variants such as an unpadded day or a different separator, so code parsing this string across engines was unreliable.
- PHP ES3 (Annex B)toGMTString() is retained as a deprecated alias referencing the exact same function object; use toUTCString().
toUTCString() produces the date format the HTTP specification uses: Wed, 05 Oct 2011 14:48:00 GMT. If you are writing a Set-Cookie Expires attribute, a Last-Modified value, or anything else that has to match RFC 7231, this is the method — none of the other Date formatters produce a string those parsers accept.
UTC regardless of the host
Like toISOString(), it ignores the host time zone entirely, so the same instant renders identically everywhere. That is the whole point for protocol use.
Choosing between this and toISOString
| toUTCString() | toISOString() | |
|---|---|---|
| Shape | Wed, 05 Oct 2011 14:48:00 GMT | 2011-10-05T14:48:00.000Z |
| Milliseconds | No | Always |
| Sorts as text | No | Yes |
| Invalid date | "Invalid Date" | Throws RangeError |
Use toUTCString() for HTTP headers and human-readable UTC output; use toISOString() for JSON, storage and sorting.
toGMTString is the same function
Date.prototype.toGMTString is not a separate implementation — it is literally the same function object, kept only for legacy compatibility. Do not use it in new code.
Note that the seconds field is present but milliseconds are discarded, so round-tripping through this string loses sub-second precision.
Example
When to use it
- Building a Set-Cookie Expires value or a Last-Modified header
- Printing a UTC timestamp in a log that humans read directly
- Producing a date string an HTTP-date parser will accept
Frequently asked questions
What date format do HTTP headers need?
The RFC 7231 format, which is exactly what toUTCString() produces: "Wed, 05 Oct 2011 14:48:00 GMT". Use it for Expires, Last-Modified and If-Modified-Since values.
What is the difference between toUTCString and toISOString?
Both render UTC, but toUTCString() uses the human-readable HTTP format without milliseconds, while toISOString() uses the sortable ISO 8601 format that always includes milliseconds and a trailing Z.
Should I use toGMTString instead?
No — toGMTString is a deprecated alias that references the exact same function object as toUTCString, kept only for legacy compatibility.
More examples
Round-trip through the HTTP format
Date can parse its own toUTCString() output, but the difference of 500 shows the milliseconds were lost on the way out.
const original = new Date(Date.UTC(2024, 5, 14, 7, 0, 0, 500));
const header = original.toUTCString();
const parsed = new Date(header);
console.log(header);
console.log(parsed.toISOString());
console.log(original.valueOf() - parsed.valueOf());Same instant, three renderings
Both formats describe the same UTC instant; only the shape differs, and both carry an explicit zone marker so neither depends on the host.
const d = new Date(Date.UTC(2024, 2, 10, 2, 30));
console.log(d.toUTCString());
console.log(d.toISOString());
console.log(d.toUTCString().endsWith("GMT"), d.toISOString().endsWith("Z"));toGMTString is an alias
The strict equality check confirms they are the same function object, not two implementations that happen to agree. toGMTString exists only for legacy code.
console.log(Date.prototype.toGMTString === Date.prototype.toUTCString);
const d = new Date(Date.UTC(1999, 11, 31, 23, 59, 59));
console.log(d.toUTCString());
console.log(d.toGMTString());
Discussion