JavaScript getDate() method explained with code examples
The JavaScript getDate() method is a method of the Date object that allows you to retrieve the day of the month of a given date.
This method has no parameters and can be called from any valid Date object.
Here’s an example of the getDate() method in action:
const date = new Date(); // 22nd March 2022 local time
const day = date.getDate();
console.log(day); // 22
The getDate() method will return an integer number between 1 and 31 that represents the day of the month.
You can get the day of the month from a specified date like this:
const date = new Date("January 01, 2010 10:20:20");
const day = date.getDate();
console.log(day); // 1
And that’s how the getDate() method works. 😉
More JavaScript tutorials
See allJavaScript
Sort Keys in Map Using JavaScript
Dec 11, 2023
JavaScript
Get Element by Data Attribute Using JavaScript
Dec 8, 2023
JavaScript
Convert Milliseconds to Hours Minutes Seconds in JavaScript
Dec 6, 2023
JavaScript
JavaScript Get the Index of Max Value in Array
Nov 16, 2023
JavaScript
JavaScript Check if Value is an Object
Nov 15, 2023