Home >Web Front-end >JS Tutorial >JavaScript converts the Date object into a string according to Greenwich Time and returns the result toGMTString()

JavaScript converts the Date object into a string according to Greenwich Time and returns the result toGMTString()

黄舟
黄舟Original
2017-11-08 13:12:372289browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn