Definition and Usage
toGMTString() method converts a Date object to a String based on Greenwich Mean Time (GMT) and returns the result.
Syntax
dateObject.toGMTString()
Return value
String representation of dateObject. The date is converted from the local time zone to the GMT time zone before being converted to a string.
Tips and Comments
This method is deprecated. Please use toUTCString() instead! !
Example
Example 1
In this example we will convert today's date to (according to GMT) a string:
<script type="text/javascript"> var d = new Date() document.write (d.toGMTString()) </script>
Output:
Wed, 08 Nov 2017 03:40:36 GMT
Example 2
In the following example, we will convert a specific date into a string (according to GMT):
<script type="text/javascript"> var born = new Date("July 21, 1983 01:15:00") document.write(born.toGMTString()) </script>
Output:
Wed, 20 Jul 1983 17:15:00 GMT
Example:
<script type="text/javascript"> var d = new Date() document.write (d.toGMTString()) </script>
Result:
Wed, 08 Nov 2017 05:13:34 GMT
The above is the detailed content of JavaScript converts the Date object into a string according to Greenwich Time and returns the result toGMTString(). For more information, please follow other related articles on the PHP Chinese website!