toUTCString() method of
Date instances returns a string representing this date in the RFC 7231 format, with negative years allowed. The timezone is always UTC.
toGMTString() is an alias of this method.
A string representing the given date using the UTC time zone (see description for the format). Returns
"Invalid Date" if the date is invalid.
The value returned by
toUTCString() is a string in the form
Www, dd Mmm yyyy hh:mm:ss GMT, where:
||Day of week, as three letters (e.g.
||Day of month, as two digits with leading zero if required|
||Month, as three letters (e.g.
||Year, as four or more digits with leading zeroes if required|
||Hour, as two digits with leading zero if required|
||Minute, as two digits with leading zero if required|
||Seconds, as two digits with leading zero if required|
Date API was inspired by Java's
java.util.Date library (while the latter had become de facto legacy since Java 1.1 in 1997). In particular, the Java
Date class had a method called
toGMTString remains as an alias to
toUTCString, and they refer to the exact same function object. This means:
Date.prototype.toGMTString.name === "toUTCString";
const d = new Date(0); console.log(d.toUTCString()); // 'Thu, 01 Jan 1970 00:00:00 GMT'
|ECMAScript Language Specification |
BCD tables only load in the browser