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

How to get time in JS

韦小宝
Release: 2017-11-28 10:27:48
Original
1442 people have browsed it

The examples in this article describe the JS method of obtaining time, and provide the JS source code. The source code can provide us with the JS and use it ~ let’s come together Let's see!

The method is as follows:

<html>  
<head>  
    <title></title>  
    <script type="text/javascript">  
        function Case(i) {  
            if (i < 10) {  
                i = "0" + i;  
            }  
            return i;  
        }  
        function getdata() {  
            var bnt = document.getElementById("id1")  
            var date = new Date();  
            bnt.value =Case( date.getHours()) + ":" + Case(date.getMinutes()) + ":" +Case( date.getSeconds());  
        }  
    </script>  
</head>  
<body>  
<input type="button" value="获取时间" id="id1" onclick="setInterval(getdata, 1000)"/>  
</body>  
</html>
Copy after login

The above is the source code of js to get the time, you can refer to it, more Please go to PHP Chinese website to search for the content~

##Related recommendations:

JS partial printing method

Common methods of native js are organized

js obtain time function and extension Function method

The above is the detailed content of How to get time in JS. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!