Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 15:55:42
Original
1294 people have browsed it

The javascript Date.setMonth() method sets the specified date of each month according to local time.
Grammar

Date.setMonth(monthValue[, dayValue])

Copy after login

Note: Appearance and data within brackets are optional

Here are the details of the parameters:

  • monthValue: an integer from 0 to 11 (representing a month, from January to December).
  • dayValue: an integer from 1 to 31, representing a day of the month.
  • msValue: A number between 0 and 999, representing milliseconds. If you specify the msValue parameter, you must also specify minutesValue and secondsValue.

If the dayValue parameter is not specified, the value returned from the getDate method is used. If the specified argument is outside the expected range, setMonth attempts to update the Date object's latest information accordingly. For example, if you use monthValue as 15, year will be incremented by 1 (year 1), and 3 will be used for the month value.
Return value:

  • NA

Example:

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

Copy after login

This will produce the following results:

Fri Mar 28 23:30:00 UTC+0530 2008 

Copy after login

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!