JavaScript Date getUTCDate()
Syntax & Examples


getUTCDate() method

The getUTCDate() method of the Date object in JavaScript returns the day (date) of the month (1 – 31) in the specified date according to universal time.


Syntax of getUTCDate()

The syntax of Date.getUTCDate() method is:

getUTCDate()

This getUTCDate() method of Date returns the day (date) of the month (1 – 31) in the specified date according to universal time.

Return Type

Date.getUTCDate() returns value of type Number.



✐ Examples

1 Using getUTCDate() to get the UTC date of a specific date

In JavaScript, we can use the getUTCDate() method to get the day of the month from a Date object according to universal time.

For example,

  1. We create a new Date object date representing January 15, 2021.
  2. We use the getUTCDate() method to get the day of the month from date.
  3. The day of the month is stored in the variable utcDate.
  4. We log utcDate to the console using console.log() method.

JavaScript Program

const date = new Date('2021-01-15');
const utcDate = date.getUTCDate();
console.log(utcDate);

Output

15

2 Using getUTCDate() with the current date

In JavaScript, we can use the getUTCDate() method to get the current day of the month from the current date according to universal time.

For example,

  1. We create a new Date object now representing the current date and time.
  2. We use the getUTCDate() method to get the current day of the month from now.
  3. The current day of the month is stored in the variable currentUTCDate.
  4. We log currentUTCDate to the console using console.log() method.

JavaScript Program

const now = new Date();
const currentUTCDate = now.getUTCDate();
console.log(currentUTCDate);

Output

31

3 Using getUTCDate() with a specific date in the past

In JavaScript, we can use the getUTCDate() method to get the day of the month from a specific date in the past according to universal time.

For example,

  1. We create a new Date object pastDate representing July 4, 1776.
  2. We use the getUTCDate() method to get the day of the month from pastDate.
  3. The day of the month is stored in the variable pastUTCDate.
  4. We log pastUTCDate to the console using console.log() method.

JavaScript Program

const pastDate = new Date('1776-07-04');
const pastUTCDate = pastDate.getUTCDate();
console.log(pastUTCDate);

Output

4

Summary

In this JavaScript tutorial, we learned about getUTCDate() method of Date: the syntax and few working examples with output and detailed explanation for each example.