How to use getDate(), getMonth(), and getFullYear() Methods In Javascript
- 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.
Example: In this example, we will be extracting Day, Month, and Year from the Date object in JavaScript using getDate(), getMonth(), and getFullYear() methods.
Javascript
let obj = new Date(); let day = obj.getDate(); let month = obj.getMonth() + 1; let year = obj.getFullYear(); 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
Contact Us