Js real-time acquisition and display of the current time method, js real-time acquisition of the current time
This example describes how to obtain and display the current time in Javascript in real time. Share it with you for your reference. The specific implementation method is as follows:
The js section is as follows:
<Script type = "text/javascript"> window. onload = function () {var show = document. getElementById ("show"); setInterval (function () {var time = new Date (); // after the month of the program timer starts from 0, + 1 var m = time. getMonth () + 1; var t = time. getFullYear () + "-" + m + "-" + time. getDate () + "" + time. getHours () + ":" + time. getMinutes () + ":" + time. getSeconds (); show. innerHTML = t ;}, 1000) ;}; </script>
The html section is as follows:
Copy codeThe Code is as follows: <div id = "show"> </div>
The displayed values are as follows:
I hope this article will help you design javascript programs.