运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Dates</h1> <p>Add zeros and colons to display the time:</p> <p id="demo"></p> <script> function addZero(i) { if (i < 10) {i = "0" + i} return i; } const d = new Date(); let h = addZero(d.getHours()); let m = addZero(d.getMinutes()); let s = addZero(d.getSeconds()); let time = h + ":" + m + ":" + s; document.getElementById("demo").innerHTML = time; </script> </body> </html>