Home  >  Article  >  Web Front-end  >  How to get time in JS

How to get time in JS

韦小宝
韦小宝Original
2017-11-28 10:27:481495browse

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>

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!

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