Home > Web Front-end > JS Tutorial > body text

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

黄舟
Release: 2017-11-08 13:12:37
Original
2242 people have browsed it

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()
Copy after login

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>
Copy after login

Output:

Wed, 08 Nov 2017 03:40:36 GMT
Copy after login

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>
Copy after login

Output:

Wed, 20 Jul 1983 17:15:00 GMT
Copy after login

Example:




<script type="text/javascript">

var d = new Date()
document.write (d.toGMTString())

</script>


Copy after login

Result:

Wed, 08 Nov 2017 05:13:34 GMT
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!