formatting

Date.prototype.toUTCString

Returns the date as a string in the older RFC 7231 / IMF-fixdate format, e.g. 'Sun, 19 Jul 2026 00:00:00 GMT'. This is the exact format required by HTTP headers like Date, Expires, and cookies.

date.toUTCString()

Parameters

Parameter Purpose
() no arguments; returns fixed English UTC string
HTTP matches the Date/Expires/Set-Cookie header format

Examples

console.log(new Date('2026-07-19T00:00:00Z').toUTCString()); // 'Sun, 19 Jul 2026 00:00:00 GMT'

HTTP-style

// Cookie expiry
document.cookie = 'k=v; expires=' + new Date(Date.now()+864e5).toUTCString();

cookie 1 day

console.log(new Date('2026-07-19T00:00:00Z').toISOString()); // '2026-07-19T00:00:00.000Z' - different format

vs toISOString

Gotcha

toUTCString suffix is 'GMT' (RFC 7231), not 'Z' - do not use it as an API payload; use toISOString for that.

Related

← All JS Date methods · Math methods · Cron syntax