Home > Web Front-end > JS Tutorial > JavaScript method setFullYear() for setting the year

JavaScript method setFullYear() for setting the year

黄舟
Release: 2017-11-07 11:37:04
Original
2657 people have browsed it

Definition and Usage

The setFullYear() method is used to set the year.

Syntax

dateObject.setFullYear(year,month,day)
Copy after login
ParametersDescription
year Required. A four-digit integer representing the year. Expressed in local time.
monthOptional. A numerical value representing the month, between 0 and 11. Expressed in local time.
day Optional. Represents the value of a certain day of the month, between 1 and 31. Expressed in local time.

Return Value

Returns the millisecond representation of the adjusted date.

Tips and Comments:

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

Example

Example 1

In this example, we will set the year to 1992 through setFullYear():

<script type="text/javascript">

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

</script>
Copy after login

Output:

Sat Nov 07 1992 11:35:49 GMT+0800 (中国标准时间)
Copy after login

Example 2

In this example, we will set the date to November 3, 1992 via setFullYear():

<script type="text/javascript">

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

</script>
Copy after login

Output:

Tue Nov 03 1992 11:35:49 GMT+0800 (中国标准时间)
Copy after login

Example:

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

This will produce the following results:

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

The above is the detailed content of JavaScript method setFullYear() for setting the year. 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