JavaScript Date getUTCMonth()

Posted by

Method

JavaScript Date getUTCMonth() Method

The getUTCMonth() method of the Date object is used to get the month of the specified date according to universal time (UTC). This method returns the month as an integer number, starting from 0 for January to 11 for December.

Syntax

The syntax for the getUTCMonth() method is as follows:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

dateObj.getUTCMonth()

[/dm_code_snippet]

Where dateObj is a valid Date object.

Return Value

The getUTCMonth() method returns an integer between 0 and 11, representing the month of the specified date according to universal time (UTC).

Example

Let’s look at an example of using the getUTCMonth() method.

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

var d = new Date("January 1, 2020 12:00:00");

var month = d.getUTCMonth();

document.write(month);

[/dm_code_snippet]

The output of the above code is:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

0

[/dm_code_snippet]

As you can see, the getUTCMonth() method returned 0, which is the integer representation of January.

Browser Support

The getUTCMonth() method is supported in all modern browsers, including Google Chrome, Mozilla Firefox, Safari, and Microsoft Edge.