Home > Web Front-end > JS Tutorial > The JavaScript method getUTCFulYear() returns a four-digit number representing the year according to Universal Time (UTC)

The JavaScript method getUTCFulYear() returns a four-digit number representing the year according to Universal Time (UTC)

黄舟
Release: 2017-11-06 14:23:48
Original
1002 people have browsed it

Definition and Usage

The getUTCFulYear() method returns the four-digit number of the year in Universal Time (UTC).

Syntax

dateObject.getUTCFullYear()
Copy after login

Return value

Returns dateObject to represent the year in universal time. The value is a four-digit integer, not two Abbreviation for number of digits.

Tips and Comments:

Comments: This method is always used in conjunction with a Date object.

Tip: For more information about Universal Coordinated Time (UTC), please refer to Baidu Encyclopedia.

Example

Example 1

In this example we get and output the current year:

<script type="text/javascript">

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

</script>
Copy after login

Output:

2017
Copy after login

Example 2

In this example we extract the year from a specific date:

<script type="text/javascript">

var born = new Date("July 21, 1983 01:15:00")
document.write("I was born in " + born.getUTCFullYear())

</script>
Copy after login

Output:

I was born in 1983
Copy after login

According to universal time on the specified date, the javascript Date.getUTCFulYear() method returns year. The value returned by getUTCFullYear is an absolute number corresponding to the year 2000, for example, 2008.

Example:

<html>
<head>
<title>JavaScript getUTCFullYear Method</title>
</head>
<body>
<script type="text/javascript">
  var dt = new Date( "December 25, 1995 23:15:20" );
  document.write("getUTCFullYear() : " + dt.getUTCFullYear() ); 
</script>
</body>
</html>
Copy after login

This will produce the following results for India time zone:

getUTCFullYear() : 1995
Copy after login

The above is the detailed content of The JavaScript method getUTCFulYear() returns a four-digit number representing the year according to Universal Time (UTC). 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