要求:在网页中显示当前时间
预览效果:
JS练习_获取当前时间_html

源码:

    let h1 = document.querySelector("h1");
setInterval(()=>{
    let timeNow = new Date();
    let hours = timeNow.getHours();
    let minuts = timeNow.getMinutes();
    let seconds = timeNow.getSeconds();
    let time = `${hours}:${minuts}:${seconds}`;
    h1.innerHTML = time;
},500)
把最实用的经验,分享给最需要的读者,希望每一位来访的朋友都能有所收获!