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>
相关推荐
浮游本尊21 分钟前
React 18.x 学习计划 - 第八天:React测试
前端·学习·react.js
麦麦在写代码25 分钟前
前端学习1
前端·学习
sg_knight29 分钟前
微信小程序中 WebView 组件的使用与应用场景
前端·javascript·微信·微信小程序·小程序·web·weapp
凯子坚持 c1 小时前
生产级 Rust Web 应用架构:使用 Axum 实现模块化设计与健壮的错误处理
前端·架构·rust
IT_陈寒1 小时前
Python 3.12新特性实战:5个让你的代码效率翻倍的隐藏技巧!
前端·人工智能·后端
程序员小寒1 小时前
前端高频面试题之Vuex篇
前端·javascript·面试
网硕互联的小客服2 小时前
如何解决 Linux 文件系统挂载失败的问题?
linux·服务器·前端·网络·chrome
程序员爱钓鱼3 小时前
Python 编程实战 · 实用工具与库 — Flask 路由与模板
前端·后端·python
合作小小程序员小小店6 小时前
web开发,在线%超市销售%管理系统,基于idea,html,jsp,java,ssh,sql server数据库。
java·前端·sqlserver·ssh·intellij-idea
不爱学英文的码字机器7 小时前
重塑 Web 性能:用 Rust 与 WASM 构建“零开销”图像处理器
前端·rust·wasm