Retrieve Today’s Date in JavaScript

We can retrive current date, current month, current year, current time from Date using JavaScript.

<!DOCTYPE html>
<html>
<body>
<p>getDate() method is used for display today's date in JavaScript</p>
<p id="currentDateDate"></p>
<p id="currentMonth"></p>
<p id="currentYear"></p>
<p id="currentFullDate"></p>
<p id="currentTime"></p>
<script>
var date = new Date();
document.getElementById("currentDateDate").innerHTML ="Current Date using JavaScript: "+date.getDate();
document.getElementById("currentMonth").innerHTML ="Current Month using JavaScript: "+(date.getMonth()+1);
document.getElementById("currentYear").innerHTML ="Current Year using JavaScript: "+date.getFullYear();
document.getElementById("currentFullDate").innerHTML ="Current Full Date using JavaScript: "+date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
document.getElementById("currentTime").innerHTML ="Current Time using JavaScript: "+date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
</script>
</body>
</html>

Once you run code, you can see the output like below:

Current Date using JavaScript: 23
Current Month using JavaScript: 9
Current Month using JavaScript: 2018
Current Full Date using JavaScript: 2018-9-23
Current Time using JavaScript: 20:58:59

Leave a Reply

Your email address will not be published.