Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript setUTCMonth() Method

JavaScript setUTCMonth() Method

Date Object Reference JavaScript Date object

Example

Set the month to 4 (April):

var d = new Date();

d.setUTCMonth(4);

d Result output:

Try it »


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 be used to set a certain day of the month.

**Note:** Coordinated Universal Time, also known as Universal Time, Universal Standard Time, or 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 value

Parameters Description
month Required. The value to set for the month field of 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 certain day of the month.

    An integer between 1 and 31, used as the day field of date Object, expressed in universal time.

    If the current month has 31 days:

    If the current month has 30 days:

    |

    Return Value

    Type Description
    Number The milliseconds representation of the adjusted date.

    Technical Details

    JavaScript version: 1.3

    More examples

    Example

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

    var d = new Date();

    d.setUTCMonth(4,20);

    d The output according to local time will be:

    Try it »

    Example

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

    var d = new Date();

    d.setUTCMonth(d.getUTCMonth(),0);

    d The output according to local time will be:

    Try it »


    Date Object Reference JavaScript Date object