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>
相关推荐
Linux-lucky4 分钟前
45-Linux学习之旅之防火墙与WEB加固
linux·前端·网络·学习·ubuntu
风骏时光牛马2 小时前
生成一个移动端标题,只需要一个标题,不需要其他的任何文本。
前端
IT_陈寒3 小时前
Redis雪崩把我坑惨了,这是5年经验的教训
前端·人工智能·后端
SameX3 小时前
HarmonyOS ArkUI List 的侧滑删除 用 ListItem 的 swipeAction + endIcon 的做法
前端
usdoc文档预览5 小时前
USDOC系列之PPT文件在线编辑-VUE前端实现在线浏览器在线编辑PPT文档
前端·vue.js·编辑器·office365·ppt在线编辑·office文件在线编辑·文件在线编辑
用户2705077725245 小时前
Agent 调工具卡住?3 种超时与取消策略实测对比
前端
LuHang6 小时前
我一行代码没写,把领导派的活做成了公司内部系统😭
前端
明月_清风6 小时前
Meta 开源了一个 AI Native 组件库:Astryx,150+ React 组件,专为 AI Agent 而设计
前端·人工智能·ai编程
用户850869276157 小时前
秒杀系统中 Shell 脚本并发控制 Bug:究竟哪里出了
前端
程序员大阳8 小时前
HTML+CSS+JS对话式实战(3)-活动管理页实现查询、新增、删除API后端接口
javascript·css·html·实战·删除·查询·新增