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>
相关推荐
2501_944424122 小时前
Flutter for OpenHarmony游戏集合App实战之连连看路径连线
android·开发语言·前端·javascript·flutter·游戏·php
search79 小时前
前端设计:CRG 3--CDC error
前端
治金的blog9 小时前
vben-admin和vite,ant-design-vue的结合的联系
前端·vscode
利刃大大10 小时前
【Vue】Vue2 和 Vue3 的区别
前端·javascript·vue.js
荔枝一杯酸牛奶11 小时前
HTML 表单与表格布局实战:两个经典作业案例详解
前端·html
Charlie_lll11 小时前
学习Three.js–纹理贴图(Texture)
前端·three.js
yuguo.im12 小时前
我开源了一个 GrapesJS 插件
前端·javascript·开源·grapesjs
安且惜12 小时前
带弹窗的页面--以表格形式展示
前端·javascript·vue.js
米奇妙妙wuu12 小时前
css实现文字和边框同样的渐变色效果
css·html·css3
GISer_Jing13 小时前
AI驱动营销:业务技术栈实战(From AIGC,待总结)
前端·人工智能·aigc·reactjs