Home  >  Article  >  Web Front-end  >  Detailed explanation of the use of setFullYear() method in JavaScript_Basic knowledge

Detailed explanation of the use of setFullYear() method in JavaScript_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 15:55:392060browse

The javascript Date.setFullYear() method will specify the date of the whole year according to local time.
Grammar

Date.setFullYear(yearValue[, monthValue[, dayValue]])

Note: Parameters in brackets are optional

Here are the details of the parameters:

  • yearValue: an integer specifying the numeric value of the year, for example, 2008
  • monthValue: month January to December represented by an integer from 0 to 11
  • dayValue: an integer between 1 and 31, representing the day of the month. If you specify the dayValue parameter, you must also specify monthValue

If the monthValue and dayValue parameters are not specified, the values ​​returned by the getMonth and getDate methods are used
Return value:

  • NA

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 

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