Để lấy ngày hiện tại trong JavaScript, hãy sử dụng phương thức getDate ().
Ví dụ
Bạn có thể thử chạy đoạn mã sau để lấy ngày:
<!DOCTYPE html>
<html>
<body>
<p>Today's Date</p>
<button onclick="myFunction()">Get Date</button>
<p id="test"></p>
<script>
function myFunction() {
var date = new Date();
var n = date.getDate();
document.getElementById("test").innerHTML = n;
}
</script>
</body>
</html>