Usage of the setMonth () method in JavaScript

Source: Internet
Author: User

Usage of the setMonth () method in JavaScript

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

Syntax

1

Date. setMonth (monthValue [, dayValue])

Note: The appearance and data in the brackets are optional.

The following is the detailed information about the parameters:

  • MonthValue: an integer from 0 to 11 (representing a month, from January 1, January to January 1, December ).
  • DayValue: an integer from 1 to 31, representing a day in a month.
  • MsValue: a number between 0 and 999, indicating milliseconds. If the msValue parameter is specified, minutesValue and secondsValue must also be specified.

If the dayValue parameter is not specified, the value returned from the getDate method is used. If the specified parameter is out of the expected range, setMonth tries to update the latest information of the Date object accordingly. For example, if the value of monthValue is 15, year will increase the increment of 1 (year + 1), and 3 will be used for the month value.
Return Value:

  • NA

Example:

1

2

3

4

5

6

7

8

9

10

11

12

<Html>

<Head>

<Title> JavaScript setMonth Method </title>

</Head>

<Body>

<Script type = "text/javascript">

Var dt = new Date ("Aug 28,200 8 23:30:00 ");

Dt. setMonth (2 );

Document. write (dt );

</Script>

</Body>

</Html>

This produces the following results:

1

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.