Home >Web Front-end >JS Tutorial >How to display time
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>获取当前时间</title> <script type="text/javascript"> function getDate() { var currentTime=new Date().getHours()+":"+new Date().getMinutes()+":"+new Date().getSeconds(); var span=document.getElementById("timeSpan"); span.innerHTML=currentTime; window.setTimeout(getDate,1000); } </script> </head> body> <input type="button" id="" value="获取当前时间" onclick="getDate()"/> <span id="timeSpan"></span> </body> </html>
The above is the detailed content of How to display time. For more information, please follow other related articles on the PHP Chinese website!