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>
相关推荐
LiaCode2 分钟前
一天学完 redis 的爽翻版核心知识总结
前端·后端
大刚测试开发实战3 分钟前
如何内网穿透访问本地私有化部署的TestHub
前端·后端·github
风骏时光牛马15 分钟前
# Ruby基于Rails框架实现多角色权限管理与数据分页查询完整实战代码案例
前端
米丘17 分钟前
微前端之 Web Components 完全指南
微服务·html
weedsfly17 分钟前
迭代器、生成器与异步迭代——让数据“按需流动”的艺术
前端·javascript
xiaodaoluanzha22 分钟前
迄今為止,最簡單的編程語言 Nolang
前端·后端
Csvn24 分钟前
Fetch 请求竞态终结者:AbortController 不只是用来"取消"的
前端
阡陌Jony24 分钟前
关于前端路由中的参数问题的学习(一): params,query, hash(#)
前端
阡陌Jony26 分钟前
缓存相关学习笔记(一):Service Worker 缓存
前端
假如让我当三天老蒯29 分钟前
前端跨域解决方案(学习用)
前端·javascript·面试