HTML 实时显示本地电脑时间(精确到毫秒)

html 复制代码
<!DOCTYPE html>
<html>
<head>
    <title>实时显示本地电脑时间(精确到毫秒)</title>
</head>
<body>
    <h1>本地电脑时间(精确到毫秒):</h1>
    <h1 id="clock"></h1>

    <script>
        function updateClock() {
            const now = new Date();
            const year = now.getFullYear();
            const month = String(now.getMonth() + 1).padStart(2, '0');
            const day = String(now.getDate()).padStart(2, '0');
            const hours = String(now.getHours()).padStart(2, '0');
            const minutes = String(now.getMinutes()).padStart(2, '0');
            const seconds = String(now.getSeconds()).padStart(2, '0');
            const milliseconds = String(now.getMilliseconds()).padStart(3, '0');
            
            const timeString = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}   ${milliseconds}`;
            document.getElementById('clock').textContent = timeString;
        }

        // 每毫秒更新一次时间
        setInterval(updateClock, 1);
    </script>
</body>
</html>
相关推荐
测试界柠檬1 分钟前
面试真题 | web自动化关闭浏览器,quit()和close()的区别
前端·自动化测试·软件测试·功能测试·程序人生·面试·自动化
多多*2 分钟前
OJ在线评测系统 登录页面开发 前端后端联调实现全栈开发
linux·服务器·前端·ubuntu·docker·前端框架
2301_801074153 分钟前
TypeScript异常处理
前端·javascript·typescript
小阿飞_4 分钟前
报错合计-1
前端
caperxi6 分钟前
前端开发中的防抖与节流
前端·javascript·html
霸气小男6 分钟前
react + antDesign封装图片预览组件(支持多张图片)
前端·react.js
susu10830189117 分钟前
前端css样式覆盖
前端·css
学习路上的小刘8 分钟前
vue h5 蓝牙连接 webBluetooth API
前端·javascript·vue.js
&白帝&8 分钟前
vue3常用的组件间通信
前端·javascript·vue.js
小白小白从不日白19 分钟前
react 组件通讯
前端·react.js