Home >Web Front-end >JS Tutorial >How to use the setYear() method to manipulate time in JavaScript_Basic knowledge

How to use the setYear() method to manipulate time in JavaScript_Basic knowledge

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

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

Date.setYear(yearValue)

Note: Data in brackets are optional

Here are the details of the parameters:

  • yearValue: an integer value.

Return value:

  • NA

Example:

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

This will produce the following results:

Mon Aug 28 13: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