The toUTCString method in JavaScript provides the specified date as a string formatted according to the UTC time zone.
Syntax
The syntax for the toUTCString method is illustrated as follows:
Example
dateObj.toUTCString()
Return
A string representing the specified date.
JavaScript Date toUTCString method example
In this section, we will explore the toUTCString method by examining a variety of examples.
Example 1
Let’s examine an illustration of how to retrieve the current date represented as a string.
Example
<script>
var date=new Date();
document.writeln(date.toUTCString());
</script>
Output:
Output
Thu, 09 Aug 2018 11:41:19 GMT
Example 2
Let’s examine an example that retrieves a particular date represented as a string.
Example
<script>
var date=new Date(1947, 7, 15, 20, 22, 10);
document.writeln(date.toUTCString());
</script>
Output:
Output
Fri, 15 Aug 1947 14:52:10 GMT