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