0
7.4kviews
Write a JavaScript program to display todays date and time
1 Answer
written 8.4 years ago by |
Code:
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Date();
</script>
</body>
</html>
Alternative:
Javascript code to display Current Date and Time :
<html>
<body>
<script type="text/javascript">
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
document.write("<b>" + day + "/" + month + "/" + year + "</b>")
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
document.write("<b>" + hours + ":" + minutes + " " + "</b>")
</script>
</body>
</html>