Without further ado, let’s get straight to the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <script type="text/javascript"> document.write("<span id=lblTime width='118px' height='11px' Font-Size='9pt' style='color:Red' ></span>") //输出显示日期的容器 //每1000毫秒(即1秒) 执行一次本段代码 setInterval("lblTime.innerText=new Date().toLocaleString()", 1000) </script> </div> </form> </body> </html>
There are also operation renderings:
Isn’t it very simple? This is the most basic method of dynamically displaying time changes on a page. You can innovate on this basis and add some styles. I hope this article will help you master javascript to achieve dynamic display of date and time. .