JavaScript Date getUTCMonth() method - JavaScript Tutorial

JavaScript Date getUTCMonth() method

BLUF: This tutorial on JavaScript Date getUTCMonth() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Date getUTCMonth() method

Understanding JavaScript Date getUTCMonth() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

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:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience