Home > Web Front-end > Front-end Q&A > How to get only the date in javascript

How to get only the date in javascript

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2022-01-17 17:29:48
Original
3026 people have browsed it

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()
Copy after login

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>
Copy after login

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!

Related labels:
Statement of this Website
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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template