Home > Article > Web Front-end > JavaScript dynamically displays the current date and time in a web page
JavaScript code: dynamically display the current date and time in the web page
<html> <head> <title>在网页中动态显示当前日期和时间</title> </head> <body onload="showTime()"> <script language="JavaScript"> function showTime(){ var thetime=new Date(); // 初始化日期对象 document.getElementById( "timeArea").innerText = thetime.toLocaleString(); window.setTimeout( "showTime()",1000); //setTimeout (表达式,延时时间)其中延时时间以豪秒为单位(1000ms=1s) } </script> <div id="timeArea" align="center"> </div> </body> </html>