JavaScript Date setUTCMonth() Method

Definition and Usage

setUTCMonth() The method sets the month according to the UTC (from 0 to 11).

Note:January is 0, February is 1, and so on.

This method can also be used to set the date in the month.

Tip:Coordinated Universal Time (UTC) is the time set by the world time standard.

Note:UTC time is the same as GMT time (Greenwich Mean Time).

Example

Example 1

Set the month to 4 (May):

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

Try It Yourself

Example 2

Set the month to 4 (May) and the date to 20th:

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

Try It Yourself

Example 3

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

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

Try It Yourself

Syntax

Date.setUTCMonth(month, day)

Parameter Value

Parameter Description
month

Required. An integer representing the month.

Expected value is 0-11, but other values are allowed:

  • -1 will result in the last month of the previous year
  • 12 will result in the first month of the following year
  • 13 will result in the second month of the following year
day

Optional. An integer representing the day of the month.

Expected value is 1-31, but other values are allowed:

  • 0 will result in the last hour of the previous month
  • -1 will result in one hour before the last hour of the previous month

If a month has 31 days:

  • 32 will result in the first day of the following month

If a month has 30 days:

  • 32 will result in the second day of the following month

Technical Details

Return Value: A numerical value representing the number of milliseconds between the date object and midnight of January 1, 1970.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
setUTCMonth() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JavaScript Date Setting Methods