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>
相关推荐
深海鱼在掘金2 分钟前
Next.js从入门到实战保姆级教程(第四章):路由系统详解
前端·typescript·next.js
leafyyuki4 分钟前
从零到一落地「智能助手」:一次基于 OpenSpec 的流式对话前端实践
前端·vue.js·人工智能
踩着两条虫5 分钟前
VTJ:架构设计模式
前端·架构·ai编程
孙凯亮6 分钟前
Three.js VR 模拟器(Immersive Web Emulator)踩坑全记录:从报错到可用,避坑指南一次性奉上
前端·three.js
CDN3606 分钟前
2026年Web性能优化实测:360CDN如何通过“时效性”与“地域性”双杀提升排名?
前端·性能优化
Dxy123931021615 分钟前
Python使用XPath定位元素:and和or组合条件
前端·javascript·python
李剑一20 分钟前
可以说99%的前端都没咋用过!JS逗号操作符,面试常考但业务少用?一篇吃透不踩坑
前端
百结21421 分钟前
HAProxy 搭建 Web 集群
前端·web
GISer_Jing26 分钟前
Todos
前端·人工智能·学习