JavaScript setUTCMonth()Method

Date 对象参考手册JavaScript Date Object

Examples

Set the month to 4 (April):

var d = new Date();
d.setUTCMonth(4);

dResult output:


Try it Yourself »

Definition and Usage

The setUTCMonth() method is used to set the month according to Universal Time (UTC).

Note:0 (January) ~ 11 (December)

This method can also be used to set a specific day of the month.

Tip:Coordinated Universal Time, also known as World Unified Time, World Standard Time, International Coordinated Time, abbreviated as UTC (Universal Coordinated Time).


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the setUTCMonth() method.


Syntax

Date.setUTCMonth(month,day)

Parameter Values

Parameter Description
month Required. The value to set for the month field of the dateObject, expressed in Universal Time.

This parameter is an integer between 0 (January) and 11 (December):

  • -1 is the last month of the previous year.
  • 12 is the first month of the next year.
  • 13 is the second month of the next year.
day Optional. A particular day of the month.

An integer between 1 and 31, used as the day field of the dateObject, expressed in Universal Time.

  • 0 is the last hour of the previous month.
  • -1 is the hour before the last hour of the previous month.

If the current month has 31 days:

  • 32 is the first day of the next month.

If the current month has 30 days:

  • 32 is the second day of the next month.

Return Value

Type Description
Number The millisecond representation of the adjusted date.

Technical Details

JavaScript Version: 1.3


More Examples

Examples

The following example sets the month to 4 (April) and the date to the 20th:

var d = new Date();
d.setUTCMonth(4,20);

dOutput in local time:


Try it Yourself »

Examples

Set the date to the last day of the previous month:

var d = new Date();
d.setUTCMonth(d.getUTCMonth(),0);

dOutput in local time:


Try it Yourself »


Date 对象参考手册JavaScript Date Object

Other Extensions