Home  >  Article  >  Web Front-end  >  How to get only the date in javascript

How to get only the date in javascript

WBOY
WBOYOriginal
2022-01-17 17:29:482840browse

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()".

How to get only the date in javascript

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:

How to get only the date in javascript

##[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn