Home > Web Front-end > JS Tutorial > body text

JavaScript dynamically displays the current date and time in a web page

高洛峰
Release: 2016-11-26 09:13:02
Original
1878 people have browsed it

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>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template