YouTip LogoYouTip

Jsref Toutcstring

```\n\nJavaScript toUTCString() Method | Novice Tutorial\n\n

JavaScript toUTCString() Method | Novice Tutorial

\n

Definition and Usage

\n

The toUTCString() method converts a Date object to a string according to universal time (UTC).

\n

Grammar

\n
dateObject.toUTCString()
\n

Return Value

\n

Returns a string representation of dateObject in UTC format.

\n

Description

\n

The returned string format is: Www, dd Mmm yyyy hh:mm:ss GMT

\n

Field Description:

\n
    \n
  • Www: Day of the week abbreviation (three letters)
  • \n
  • dd: Day (two digits, if less than 10, add leading zero)
  • \n
  • Mmm: Month abbreviation (three letters)
  • \n
  • yyyy: Four-digit year
  • \n
  • hh: Hour (two digits, if less than 10, add leading zero)
  • \n
  • mm: Minute (two digits, if less than 10, add leading zero)
  • \n
  • ss: Second (two digits, if less than 10, add leading zero)
  • \n
\n

Browser Support

\n

All major browsers support the toUTCString() method.

\n

Examples

\n

Example 1

\n

In this example, we will convert today's date to a string according to UTC:

\n
var d = new Date();\nvar n = d.toUTCString();\ndocument.getElementById("demo").innerHTML = n;
\n

Output:

\n
Thu,μ‹€ν–‰ μ‹œμ μ— 따라 좜λ ₯ 닀름, 예: Thu, 28 Dec 2023specific date and time> GMT
\n

Example 2

\n

Convert a specific date object to a UTC string:

\n
var d = new Date("July 21, 1983 01:15:00");\nvar n = d.toUTCString();\ndocument.getElementById("demo").innerHTML = n;
\n

Output:

\n
Wed, 20 Jul 1983 17:15:00 GMT
\n

Related References

\n

JavaScript Date Object Reference

\n\n```
← Jsref UtcJsref Totimestring β†’