Home > Article > Web Front-end > How to get time in JS
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:
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!