Definition and Usage
toUTCString() method can convert Date object to String according to Universal Time (UTC), and return the result.
Syntax
dateObject.toUTCString()
Return value
String representation of dateObject, expressed in universal time.
Example
Example 1
In the following example, we will use toUTCString() to convert today's date to a string (according to UTC):
<script type="text/javascript"> var d = new Date() document.write (d.toUTCString()) </script>
Output:
Wed, 08 Nov 2017 05:21:56 GMT
Example 2
In the following example, we will convert a specific date into a string (according to UTC):
<script type="text/javascript"> var born = new Date("July 21, 1983 01:15:00") document.write(born.toUTCString()) </script>
Output :
Wed, 20 Jul 1983 17:15:00 GMT
How to use toUTCString() to convert today's date to a string (according to UTC).
<script type="text/javascript"> var d = new Date() document.write (d.toUTCString()) </script>
Result:
Wed, 08 Nov 2017 05:23:18 GMT
The above is the detailed content of The JavaScript method toUTCString() converts a Date object into a string according to universal time and returns the result.. For more information, please follow other related articles on the PHP Chinese website!