How to use getUTCDate(), getUTCMonth(), and getUTCFullYear() Methods In Javascript

  • In this method, we are using built-in methods like getUTCDate() to get the day of the month.
  • The getUTCMonth() method to extract the month (Adding 1 because months are zero-indexed).
  • The getUTCFullYear() method to get the full year from the Date object in UTC format.

Example: In this example, we will be extracting Day, Month, and Year from the Date object in JavaScript using getUTCDate(), getUTCMonth(), and getUTCFullYear() methods.

Javascript




let obj = new Date();
let day = obj.getUTCDate();
let month = obj.getUTCMonth() + 1;
let year = obj.getUTCFullYear();
console.log(`Day: ${day}, Month: ${month}, Year: ${year}`);


Output

Day: 26, Month: 11, Year: 2023

How to get Day Month and Year from Date Object in JavaScript ?

We have given the Date object and the task is to extract the Day, Month, and Year from the Date object and print it using JavaScript. Below is an example for better understanding.

Example:

Input: Date Object
Output: Day: 26 Month: 11 Year: 2023

To extract Day, Month, and Year from Date Object, we have three different methods which are stated below:

Table of Content

  • Using getUTCDate(), getUTCMonth(), and getUTCFullYear() Methods
  • Using getDate(), getMonth(), and getFullYear() Methods
  • Using toLocaleDateString() Method

Similar Reads

Method 1: Using getUTCDate(), getUTCMonth(), and getUTCFullYear() Methods

In this method, we are using built-in methods like getUTCDate() to get the day of the month. The getUTCMonth() method to extract the month (Adding 1 because months are zero-indexed). The getUTCFullYear() method to get the full year from the Date object in UTC format....

Method 2: Using getDate(), getMonth(), and getFullYear() Methods

...

Method 3: Using toLocaleDateString() Method

In this method, we have used local time methods like getDate() to retrieve the date of the month. The getMonth() method to get the month of the Date. The getFullYear() to get the full year from the Date object. This method provides the local time zone for the user to extract the day, month, and year from the Date object....

Contact Us