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
getFullYear to get full year.
const date = new Date(); const year = date.getFullYear(); console.log(year);
We can also get a full year of a specific date.
// Specific date 👇️👇️ const date = new Date('January 25, 2030 05:24:07'); const yearOfDate = date.getFullYear(); console.log(yearOfDate);
What if we want to get the month?
There is also a built-in function to do this called
getMonth, so don't worry.
// 👇️ Get 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.
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. 🚀