• JavaScript Video Tutorials

JavaScript Date getUTCDate() Method



The JavaScript Date.getUTCDate() method will retrieve the "day of the month" from a Date object in Coordinated universal time (UTC). The return value will be an integer between 1 to 31, representing the day of the month. If the date is invalid, this method returns "NaN" as result. In addition to that, this method does not accept any parameters.

UTC stands for Coordinated Universal Time. It is the primary time standard by which the world regulates clocks and time. Whereas, the India Standard Time (IST) is the time observed in India, and the time difference between IST and UTC is as UTC+5:30 (i.e. 5 hours 30 minutes).

Syntax

Following is the syntax of JavaScript Date getUTCDate() method −

getUTCDate();

This method does not accepts any parameters.

Example 1

The following example demonstrates the usage of JavaScript Date getUTCDate() method −

<html>
<body>
<script>
   const currentDate = new Date();
   const dayOfMonth = currentDate.getUTCDate();

   document.write(dayOfMonth);
</script>
</body>
</html>

Output

The above program retrieves day of the month according to UTC.

Example 2

In the following example, we are providing a specific date to the date constructor.

<html>
<body>
<script>
   const specificDate = new Date('2023-12-25');
   const dayOfMonth = specificDate.getUTCDate();

   document.write(dayOfMonth);
</script>
</body>
</html>

Output

The above program retrieves "25" as the day of the month.

Example 3

If we provide a date value that doesn't lie in between 1 to 31, this method returns NaN.

<html>
<body>
<script>
   const specificDate = new Date('2023-12-45');
   const dayOfMonth = specificDate.getUTCDate();

   document.write(dayOfMonth);
</script>
</body>
</html>

Output

As we can see the output, it returned "NaN" because the date is not in between 1 to 31.

Advertisements