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)

黄舟
黄舟Original
2017-11-06 14:23:48999browse

Definition and Usage

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

Syntax

dateObject.getUTCFullYear()

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>

Output:

2017

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>

Output:

I was born in 1983

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>

This will produce the following results for India time zone:

getUTCFullYear() : 1995

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!

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