setUTCMonth()  Date  instance method JS Home  <<  JS Reference  <<  Date  <<  setUTCMonth()

Description

Sets the UTC month of the year (0-11) for the specified date.

Syntax

Signature Description
aDate.setUTCMonth(monthInt[, dayInt])Sets the UTC month of the year (0-11) for the specified date.

Parameters

Parameter Description
monthIntAn integer in the range 0-11. January=0, February=1 etc.
dayIntAn integer in the range 1-31.
  • If dayInt is not specified the value returned from the getUTCDate() method is used.
For specified values outside the ranges above the setUTCMonth() method will try and set the date accordingly.

Examples

The code below shows examples of the setUTCMonth() method of Date.



// Create a Date instance for the current date and time.
var todaysDate = new Date();
alert(todaysDate);

// Set UTC month.
todaysDate.setUTCMonth(3);
alert(todaysDate + ' UTC Month set to 3');

// Set UTC month and day.
todaysDate.setUTCMonth(7,7);
alert(todaysDate + ' UTC Month and day set');

Press the button below to action the above code:

Related Tutorials

JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times