Home >Web Front-end >JS Tutorial >JavaScript dynamically displays the current date and time in a web page

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

高洛峰
高洛峰Original
2016-11-26 09:13:021914browse

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>


Statement:
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