JavaScript Date getUTCMonth() method

The getUTCMonth method in JavaScript provides the integer representation of the month for a given date, based on Coordinated Universal Time (UTC). The integer returned by the getUTCMonth method begins at 0, where 0 corresponds to January.

Syntax

The syntax for the getUTCMonth method is as follows:

Example

dateObj.getUTCMonth()

Return

A numerical value ranging from 0 to 11 that indicates the month within the given date.

JavaScript Date getUTCMonth method example

In this section, we will explore the getUTCMonth method by examining a range of examples.

Example 1

Let’s examine an example that demonstrates how to display the current month based on Coordinated Universal Time (UTC).

Example

<script>

var month=new Date();

document.writeln("Month value : "+(month.getUTCMonth()+1));

</script>

Output:

Output

Month value : 8

Example 2

Consider the following example that illustrates how to extract and display the month from a specified date in accordance with Coordinated Universal Time (UTC).

Example

<script>

var month1=new Date("August 31, 1947 20:22:10 GMT+12:00");

var month2=new Date("August 31, 1947 20:22:10 GMT-12:00");

document.writeln("Month value1 : "+(month1.getUTCMonth()+1)+"<br>");

document.writeln("Month value2 : "+(month2.getUTCMonth()+1));

</script>

Output:

Output

Month value1 : 8

Month value2 : 9

Input Required

This code uses input(). Please provide values below: