Home >Web Front-end >JS Tutorial >Introduction to the use of setUTCFullYear() method in JavaScript_Basic knowledge

Introduction to the use of setUTCFullYear() method in JavaScript_Basic knowledge

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

The javascript Date.setUTCFulYear() method sets the whole year to the specified date according to universal time.
Grammar

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

Note: The data inside and outside the brackets are optional

Here are the details of the parameters:

  • yearValue: An integer specifying the numeric value of the year, for example, 2008.
  • monthValue: The month represented by an integer from 0 to 11, from January to December.
  • 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 from the getMonth and getDate methods are used. If the specified parameter is outside the expected range, calling setUTCFullYear attempts to update the corresponding date information of the other parameters and 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.
Return value:

  • NA

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>

This will produce the following results:

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

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