0
6.8kviews
Write a JavaScript program to display todays date and time
1 Answer
0
140views

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>
Please log in to add an answer.