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

JavaScript method setFullYear() for setting the year

黄舟
黄舟Original
2017-11-07 11:37:042635browse

Definition and Usage

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

Syntax

dateObject.setFullYear(year,month,day)
Parameters Description
year Required. A four-digit integer representing the year. Expressed in local time.
month Optional. 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>

Output:

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

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>

Output:

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

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>

This will produce the following results:

Mon Aug 28 23:30:00 UTC+0530 2000

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!

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