普通视图

发现新文章,点击刷新页面。
昨天 — 2026年1月15日首页

网页版时钟

作者 rocky191
2026年1月15日 20:45

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

image.png

<!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>

❌
❌