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>
相关推荐
葬送的代码人生5 分钟前
别再「Ctrl+C/V」了!Git 开发必备技能,10 分钟告别单机码农
前端·github·代码规范
xuankuxiaoyao6 分钟前
vue.js 设计与开发 ---路由
前端·javascript·vue.js
ZC跨境爬虫9 分钟前
跟着 MDN 学CSS day_6:(伪类和伪元素详解)
前端·javascript·css·数据库·ui·html
idcu10 分钟前
Lyt.js + Vite 快速开发指南
前端·typescript
暗不需求11 分钟前
玩转 React Hooks:从基础到实战,逐行解析带你彻底掌握
前端·react.js·面试
一颗小青松12 分钟前
css 文字区域根据图片形状显示,根据文字设置背景图
前端·css
阿黎梨梨13 分钟前
跟 Git 打交道的正确姿势
前端
idcu13 分钟前
深入 Lyt.js 路由系统:L6 生态系统层的核心
前端·typescript
idcu14 分钟前
用 Lyt.js 构建 Todo 应用:完整教程
前端·typescript
七夜zippoe14 分钟前
DolphinDB时间序列引擎:实时聚合计算
服务器·前端·时间序列·dolphindb·实时聚合