Home > Web Front-end > JS Tutorial > JavaScript method setUTCFulYear() to set the year according to Universal Time (UTC)

JavaScript method setUTCFulYear() to set the year according to Universal Time (UTC)

黄舟
Release: 2017-11-07 14:23:35
Original
1564 people have browsed it

Definition and Usage

The setUTCFullYear() method is used to set the year according to Universal Time (UTC).

Syntax

dateObject.setUTCFullYear(year,month,day)
Copy after login
ParametersDescription
year

Required. The value of the year field to set for the dateObject.

This parameter should be the complete year with century value, such as 1999, not just the abbreviated year value, such as 99.

month

Optional. The value of the month field to set for the dateObject. Expressed using world time.

This parameter is an integer between 0 ~ 11.

day

Optional. The value of the day field to be set for dateObject. Expressed using world time.

This parameter is an integer between 1 ~ 31.

Return value

Adjusted date expressed in milliseconds

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 will set the year to 1992 through the setUTCFulYear() method:

<script type="text/javascript">

var d = new Date()
d.setUTCFullYear(1992)
document.write(d)

</script>
Copy after login

Output:

Sat Nov 07 1992 14:21:20 GMT+0800 (中国标准时间)
Copy after login

Example 2

In this example, I will set the date to November 3, 1992 through the setUTCFulYear() method:

<script type="text/javascript">

var d = new Date()
d.setUTCFullYear(1992,10,3)
document.write(d)

</script>
Copy after login

Output:

Tue Nov 03 1992 14:21:20 GMT+0800 (中国标准时间)
Copy after login

If the monthValue and dayValue parameters are not specified, the values ​​returned from the getMonth and getDate methods are used. If the specified parameters are outside the expected range, call setUTCFullYear to try to update other parameters and the corresponding date information of the Date object. For example, if you specify 15 for monthValue, the year is in increments of 1 (year + 1), and 3 is used to represent the month.

Example:

<html>
<head>
<title>JavaScript setUTCFullYear Method</title>
</head>
<body>
<script type="text/javascript">
  var dt = new Date( "Aug 28, 2008 23:30:00" );
  dt.setUTCFullYear( 2006 );
  document.write( dt ); 
</script>
</body>
</html>
Copy after login

This will produce the following results:

Mon Aug 28 23:30:00 UTC+0530 2006
Copy after login

The above is the detailed content of JavaScript method setUTCFulYear() to set 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