To get only the current date number, we can use the getDate()
method from the global Date
object in JavaScript.
TL;DR
// Make an instance or object of the Date constructor
const currentDate = new Date();
// get the current date number
const dateNumber = currentDate.getDate();
console.log(dateNumber); // eg: 17
First, let's make an object (or instance) from the global Date
constructor using the new
keyword like this,
// Make an instance or object of the Date constructor
const currentDate = new Date();
Now we can use the getDate()
method from the currentDate
object to get the date number like this,
// Make an instance or object of the Date constructor
const currentDate = new Date();
// get the current date number
const dateNumber = currentDate.getDate();
console.log(dateNumber); // eg: 17
Yay, We successfully got the date number 🎉!
See the above code live in JSBin.
That's all 😃!