JavaScript Date getUTCDate()

Posted by

Method

JavaScript Date getUTCDate() Method

The getUTCDate() method in JavaScript is used to get the day of the month as per the Universal Coordinated Time (UTC) from a Date object.

Syntax

The syntax for the getUTCDate() 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.getUTCDate()

[/dm_code_snippet]

Here, dateObj is a Date object.

Return Value

The getUTCDate() method returns the day of the month as per the Universal Coordinated Time (UTC). The return value is an integer ranging from 1 to 31, representing the day of the month.

Example

Let’s look at an example to illustrate the use of the getUTCDate() 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”]

let d = new Date('June 25, 2020'); 
let day = d.getUTCDate(); 

console.log(day); 

// Output: 25

[/dm_code_snippet]

In the above example, we have created a Date object with a date string of ‘June 25, 2020’. We have then used the getUTCDate() method to get the day of the month as per the Universal Coordinated Time (UTC). The output of the above example is 25, which is the day of the month.

Browser Support

The getUTCDate() method is supported in all major browsers, including Chrome, Firefox, Safari, and Edge.