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}`); |
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