new Date() constructor to get a date object.
Let's see an example
const date = new Date(); console.log(date);
Of course, I have this date today, but it will be different for you.
Now that we have the full date, we will call a function called
getMonth to get full month.
const date = new Date(); const month = date.getMonth() + 1; console.log(month);
getMonth method returns the month in the specified date according to local time, as a zero-based value.
We can also get a full month of a specific date.
// Specific date 👇️👇️ const date = new Date('Feb 25, 2030 05:24:07'); const monthOfDate = date.getMonth() + 1; console.log(monthOfDate);
What if we want to get the year?
There is also a built-in function to do this called
getFullYear, so don't worry.
// 👇️ Get year const date = new Date(); const year = date.getFullYear(); console.log(year);
Well, What if we want to get the day?
// 👇️ Get Day const date = new Date(); const day = date.getDate(); console.log(day);
Thank you for reading
Thank you for reading my blog. 🚀