Latest web development tutorials

JavaScript setUTCMonth () method

Date Object Reference JavaScript Date Object

Examples

The month is set to 4 (April):

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

d resulting output:


try it"

Definition and Usage

setUTCMonth () method is used to set the month when the World (UTC).

Note: 0 (January) to 11 (December)

This method can be applied to set up a day of the month.

Tip: Coordinated Universal Time, also known as the unified world time, Universal Time, Coordinated Universal Time, abbreviated UTC (Universal Coordinated Time).


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support setUTCMonth () method


grammar

Date.setUTCMonth( month , day )

Parameter Value

参数 描述
month 必需。要给 dateObject 设置的月份字段的值,用世界时表示。

该参数是 0(一月) ~ 11(十二月) 之间的整数:

  • -1 为上一年的最后一月。
  • 12 为下一年的第一个月。
  • 13 为下一年的第二月。
day 可选。月份中的某一天。

在 1 ~ 31 之间的整数,用作 date Object 的天字段,用世界时表示。

  • 0 为上一个月的最后一小时。
  • -1 为上一个月最后一小时之前的小时时间。

如果当月有31天:

  • 32 为下一个月的第一天。

如果当月有30天:

  • 32 为下一个月的第二天。

return value

Type 描述
Number 调整过的日期的毫秒表示。

technical details

JavaScript version: 1.3


More examples

Examples

The following examples set March 4 (April) No. 20 dated:

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

d in local output:


try it"

Examples

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

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

d in local output:


try it"


Date Object Reference JavaScript Date Object