The example in this article describes how js can obtain and display the current time in real time. Share it with everyone for your reference. The specific implementation method is as follows:
The js part is as follows:
<script type="text/javascript"> window.onload = function() { var show = document.getElementById("show"); setInterval(function() { var time = new Date(); // 程序计时的月从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 part is as follows:
The displayed value is as follows:
2015-7-31 8:47:5
I hope this article will be helpful to everyone’s JavaScript programming design.