In JavaScript, you can use the getDate() method to get only the date. This method can use the Date object to return a certain day of the month, that is, only get the specified date. The syntax is "Date.getDate()".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
How to get only the date in javascript
You can use the getDate() method to get only the date.
The getDate() method returns the day of the month.
The syntax is:
Date.getDate()
The return value is a day in the month pointed by dateObject, using local time. The return value is an integer between 1 ~ 31.
The example is as follows:
<html> <head> <meta charset="utf-8"> <title>123</title> </head> <body> <p id="demo">单击按钮显示今天几号</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var d = new Date(); var x = document.getElementById("demo"); x.innerHTML=d.getDate(); } </script> </body> </html>
Output result:
##[Related recommendations:javascript learning tutorial 】
The above is the detailed content of How to get only the date in javascript. For more information, please follow other related articles on the PHP Chinese website!