In this blog post, we're taking a look at 8
date get methods and break them down in a simple way.
The methods we will cover:
Get the time using ECMAScript 5.
Date.now() method returns the number of UNIX milliseconds passed since January 1, 1970:00:00:00 UTC
Get the year as a four-digit number(yyyy)
const year = new Date().getFullYear(); //2020
Get the month as a number (0-11)
const month = new Date().getMonth() + 1; //11
To get the correct month, you must add 1.
Get the weekday as a number (0-6)
const day = new Date().getDay(); const days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", ]; days[day]; //Friday
Get the hour (0-23)
const hours = new Date().getHours(); //8
Get the minutes (0-59)
const minutes = new Date().getMinutes(); //40
Get the time in milliseconds since January 1, 1970
const time = new Date().getTime(); //159.....
Get the day as a number (1-31)
const date = new Date().getDate(); //27
💌 If you'd like to receive more tutorials in your inbox, you can sign up for the newsletter here.