牛马工作小程序(薪资实时计算、工作日倒计时)

写在前面

最近天气变热,工作郁郁寡欢,上班的小伙伴内心躁动,不想干活,于是顺手给各位小伙伴清凉一下,绿色的UI设计,人性化的秒级工资实时计算。

内容包括当前时间、离年底的工作日(因为2026节假日安排没有)、今日已工作时间、已挣工资等模块,工作时间按早9:00晚19:00计算,不符合小伙伴情况的可以自己改,日薪酬是可以页面更新的


<!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>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #e8f5e9;
            color: #2e7d32;
            text-align: center;
            padding: 20px;
            margin: 0;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: #c8e6c9;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        h1 {
            color: #1b5e20;
            margin-bottom: 30px;
        }
        .info-box {
            background-color: #a5d6a7;
            padding: 15px;
            margin: 15px 0;
            border-radius: 8px;
            font-size: 18px;
        }
        .highlight {
            font-size: 24px;
            font-weight: bold;
            color: #1b5e20;
        }
        input {
            padding: 8px;
            border-radius: 4px;
            border: 1px solid #81c784;
            margin: 5px;
            width: 120px;
        }
        button {
            background-color: #4caf50;
            color: white;
            border: none;
            padding: 10px 15px;
            border-radius: 4px;
            cursor: pointer;
            margin: 5px;
        }
        button:hover {
            background-color: #388e3c;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>工作日倒计时 & 薪酬计算器</h1>
        
        <div class="info-box">
            <p>当前日期和时间: <span id="current-time" class="highlight"></span></p>
        </div>
        
        <div class="info-box">
            <p>距离2026年1月1日还有: <span id="workdays-left" class="highlight"></span> 个工作日</p>
            <p>剩余周数: <span id="weeks-left" class="highlight"></span> 周</p>
        </div>
        
        <div class="info-box">
            <p>今日已工作时间: <span id="today-worked" class="highlight"></span></p>
            <p>今日已挣金额: ¥<span id="today-earned" class="highlight"></span></p>
        </div>
        
        <div class="info-box">
            <label for="daily-salary">每日酬劳(元):</label>
            <input type="number" id="daily-salary" value="500" min="0">
            <button onclick="updateSalary()">更新</button>
        </div>
    </div>

    <script>
        let dailySalary = 500;
        let updateInterval;
        
        function isWorkday(date) {
            const day = date.getDay();
            return day !== 0 && day !== 6;
        }
        
        function countWorkdays(startDate, endDate) {
            let count = 0;
            const current = new Date(startDate);
            
            while (current <= endDate) {
                if (isWorkday(current)) {
                    count++;
                }
                current.setDate(current.getDate() + 1);
            }
            
            return count;
        }
        
        function countWeeks(startDate, endDate) {
            const diffTime = Math.abs(endDate - startDate);
            return Math.floor(diffTime / (1000 * 60 * 60 * 24 * 7));
        }
        
        function formatTime(seconds) {
            const hrs = Math.floor(seconds / 3600);
            const mins = Math.floor((seconds % 3600) / 60);
            const secs = seconds % 60;
            return `${hrs.toString().padStart(2, '0')}:${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
        }
        
        function calculateTodayEarnings() {
            const now = new Date();
            const startOfWork = new Date(now);
            startOfWork.setHours(9, 0, 0, 0);
            
            const endOfWork = new Date(now);
            endOfWork.setHours(19, 0, 0, 0);
            
            if (now < startOfWork) {
                return { workedSeconds: 0, earned: 0 };
            }
            
            const endTime = now > endOfWork ? endOfWork : now;
            const workedSeconds = Math.floor((endTime - startOfWork) / 1000);
            const totalWorkSeconds = 10 * 3600;
            const earned = (workedSeconds / totalWorkSeconds) * dailySalary;
            
            return {
                workedSeconds,
                earned: earned.toFixed(2)
            };
        }
        
        function updateDisplay() {
            const now = new Date();
            document.getElementById('current-time').textContent = now.toLocaleString('zh-CN');
            
            const endDate = new Date('2026-01-01');
            const workdaysLeft = countWorkdays(now, endDate);
            const weeksLeft = countWeeks(now, endDate);
            
            document.getElementById('workdays-left').textContent = workdaysLeft;
            document.getElementById('weeks-left').textContent = weeksLeft;
            
            if (isWorkday(now)) {
                const { workedSeconds, earned } = calculateTodayEarnings();
                document.getElementById('today-worked').textContent = formatTime(workedSeconds);
                document.getElementById('today-earned').textContent = earned;
            } else {
                document.getElementById('today-worked').textContent = "今天是休息日";
                document.getElementById('today-earned').textContent = "0.00";
            }
        }
        
        function updateSalary() {
            const newSalary = parseFloat(document.getElementById('daily-salary').value);
            if (!isNaN(newSalary) && newSalary >= 0) {
                dailySalary = newSalary;
                updateDisplay();
            }
        }
        
        updateDisplay();
        updateInterval = setInterval(updateDisplay, 1000);
        
        window.addEventListener('beforeunload', () => {
            clearInterval(updateInterval);
        });
    </script>
</body>
</html>

各位清凉一夏吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

百老

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值