Home > Web Front-end > JS Tutorial > The JavaScript method toUTCString() converts a Date object into a string according to universal time and returns the result.

The JavaScript method toUTCString() converts a Date object into a string according to universal time and returns the result.

黄舟
Release: 2017-11-08 13:22:19
Original
1743 people have browsed it

Definition and Usage

toUTCString() method can convert Date object to String according to Universal Time (UTC), and return the result.

Syntax

dateObject.toUTCString()
Copy after login

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

Output:

Wed, 08 Nov 2017 05:21:56 GMT
Copy after login

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

Output :

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

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>


Copy after login

Result:

Wed, 08 Nov 2017 05:23:18 GMT
Copy after login


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!

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