Method
Introduction to the JavaScript Date getDate() Method
The JavaScript Date getDate() method is used to get the day of the month of a given date. This method is used to retrieve the day of the month for the specified date according to local time. The returned value is an integer between 1 and 31, representing the day of the month.
Syntax of the JavaScript Date getDate() Method
The syntax for the JavaScript Date getDate() method is as follows:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
dateObj.getDate()
[/dm_code_snippet]
Parameters of the JavaScript Date getDate() Method
The JavaScript Date getDate() method does not accept any parameters.
Return Value of the JavaScript Date getDate() Method
The JavaScript Date getDate() method returns an integer between 1 and 31 representing the day of the month.
Examples of the JavaScript Date getDate() Method
Let’s look at some examples of the JavaScript Date getDate() method to understand how it works:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
// Create a new date object var date = new Date(); // Get the day of the month var day = date.getDate(); // Display the day of the month document.write(day);
[/dm_code_snippet]
In the above example, we have created a new date object and then used the getDate() method to get the day of the month. The result is displayed on the web page.
Browser Support for the JavaScript Date getDate() Method
The JavaScript Date getDate() method is supported in all modern web browsers, including Chrome, Firefox, Safari, Edge, and Internet Explorer.
Conclusion
The JavaScript Date getDate() method is used to get the day of the month of a given date. This method is used to retrieve the day of the month for the specified date according to local time. The returned value is an integer between 1 and 31, representing the day of the month. The JavaScript Date getDate() method is supported in all modern web browsers.