Este artigo descreve o método de obtenção de tempo por JS. Compartilhe para sua referência. O método de implementação específico é o seguinte:
A cópia do código é a seguinte: <html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<Title> </title>
<script type = "text/javascript">
Caso da função (i) {
if (i <10) {
i = "0" + i;
}
retornar i;
}
função 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 = "get time" id = "id1" onclick = "setInterval (getData, 1000)"/>
</body>
</html>
Espero que este artigo seja útil para a programação JavaScript de todos.