Skip to content

JavaScript Date setMonth() Method

  • by

JavaScript Date setMonth() Method is a built-in function in JavaScript’s Date object, which is used to set the numeric value of the month for a given date object.

dateObj.setMonth(month, day)

It takes one or two arguments – the first one being the month value, and the second one (optional) being the day of the month. If the day of the month is not specified, the method sets the day to the first day of the new month by default.

JavaScript Date setMonth() Method example

Simple example code.

<!DOCTYPE html>
    const date = new Date('2022-01-01');

    // Set the month to February

    // Set the month to December and day to 15
    date.setMonth(11, 15);



JavaScript Date setMonth() Method

Do comment if you have any doubts or suggestions on this JS Date method topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading