网页版时钟

之前看到类似的时钟工具,ai coding 一个类似的!浏览器全屏显示后,当成屏保,也不错。

html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数字时钟</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            background-color: #ffffff;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            padding: 20px;
            color: #333;
        }

        .container {
            text-align: center;
            max-width: 800px;
        }

        .date {
            font-size: 2.5rem;
            color: #666;
            margin-bottom: 40px;
            font-weight: 300;
        }

        .clock-container {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 8px;
            margin-bottom: 60px;
        }

        .time-segment {
            position: relative;
            width: 80px;
            height: 120px;
            background-color: #e0e0e0;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        .time-digit {
            position: absolute;
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 4rem;
            font-weight: bold;
            color: #333;
        }

        .time-separator {
            font-size: 3rem;
            color: #333;
            font-weight: bold;
        }

        .ampm {
            font-size: 2.5rem;
            color: #333;
            margin-left: 15px;
            font-weight: bold;
        }

        .quote {
            font-size: 1.2rem;
            color: #666;
            line-height: 1.6;
            margin-bottom: 20px;
            font-style: italic;
        }

        .author {
            font-size: 1rem;
            color: #888;
            text-align: right;
        }

        @media (max-width: 768px) {
            .date {
                font-size: 2rem;
            }

            .time-segment {
                width: 60px;
                height: 90px;
            }

            .time-digit {
                font-size: 3rem;
            }

            .time-separator {
                font-size: 2.5rem;
            }

            .ampm {
                font-size: 2rem;
            }

            .quote {
                font-size: 1rem;
            }
        }

        @media (max-width: 480px) {
            .date {
                font-size: 1.5rem;
            }

            .time-segment {
                width: 45px;
                height: 70px;
            }

            .time-digit {
                font-size: 2.2rem;
            }

            .time-separator {
                font-size: 2rem;
            }

            .ampm {
                font-size: 1.5rem;
            }

            .quote {
                font-size: 0.9rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="date" id="date">星期二, 九月 23 2025</div>
        
        <div class="clock-container">
            <div class="time-segment">
                <div class="time-digit" id="hour1">1</div>
            </div>
            <div class="time-segment">
                <div class="time-digit" id="hour2">1</div>
            </div>
            <div class="time-separator">:</div>
            <div class="time-segment">
                <div class="time-digit" id="minute1">3</div>
            </div>
            <div class="time-segment">
                <div class="time-digit" id="minute2">0</div>
            </div>
            <div class="time-separator">:</div>
            <div class="time-segment">
                <div class="time-digit" id="second1">3</div>
            </div>
            <div class="time-segment">
                <div class="time-digit" id="second2">8</div>
            </div>
            <div class="ampm" id="ampm">PM</div>
        </div>
        
        <div class="quote">
            "When I get a little money I buy books; and if any is left I buy food and clothes."
        </div>
        <div class="author">Desiderius Erasmus</div>
    </div>

    <script>
        // 星期和月份的中文映射
        const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
        const months = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
        
        function updateClock() {
            const now = new Date();
            
            // 获取中文日期
            const year = now.getFullYear();
            const month = now.getMonth();
            const day = now.getDate();
            const weekday = now.getDay();
            
            // 设置日期(使用中文格式)
            const dateElement = document.getElementById('date');
            dateElement.textContent = `${weekdays[weekday]}, ${months[month]} ${day} ${year}`;
            
            // Get current time
            let hours = now.getHours();
            const minutes = now.getMinutes();
            const seconds = now.getSeconds();
            const ampm = hours >= 12 ? 'PM' : 'AM';
            
            // Convert to 12-hour format
            hours = hours % 12;
            hours = hours ? hours : 12; // the hour '0' should be '12'
            
            // Format time with leading zeros
            const formattedHours = hours.toString().padStart(2, '0');
            const formattedMinutes = minutes.toString().padStart(2, '0');
            const formattedSeconds = seconds.toString().padStart(2, '0');
            
            // Update the clock display
            document.getElementById('hour1').textContent = formattedHours[0];
            document.getElementById('hour2').textContent = formattedHours[1];
            document.getElementById('minute1').textContent = formattedMinutes[0];
            document.getElementById('minute2').textContent = formattedMinutes[1];
            document.getElementById('second1').textContent = formattedSeconds[0];
            document.getElementById('second2').textContent = formattedSeconds[1];
            document.getElementById('ampm').textContent = ampm;
        }
        
        // Update clock immediately and then every second
        updateClock();
        setInterval(updateClock, 1000);
    </script>
</body>
</html>
相关推荐
涛涛ing1 小时前
OpenAI Astra 泄露:零样本生成 3D 网页,前端开发者慌了吗?
前端
ssshooter2 小时前
现在网页都能提供 MCP 了?!
前端·人工智能·程序员
杉氧2 小时前
状态管理变迁史:为什么我们放弃了 Redux 选择 Zustand?
android·前端·react native
cidy_982 小时前
OpenCode 手动配置火山方舟 Agent Plan 教程
前端
鹏多多2 小时前
PC 网站接入微信登录,这 10 个坑我替你踩完了!
前端·javascript·vue.js
律宏阔2 小时前
微信小程序使用 Orval + OpenAPI 自动生成接口:Axios 兼容踩坑记录
前端·微信小程序
律宏阔2 小时前
微信小程序集成 TDesign 完整记录:解决 NPM packages not found
前端·微信小程序
律宏阔2 小时前
微信小程序 ECharts 瘦身实战:分包异步化 + componentPlaceholder 避开主包 2MB 限制
前端·微信小程序
夏天要喝冰可乐3 小时前
从 Idea 到开源插件:我用 Vibe Coding 做了「文章摆渡」
前端·ai编程·vibecoding
小小小小宇3 小时前
pi agent
前端