吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 674|回复: 5
上一主题 下一主题
收起左侧

[其他原创] 网站已运行时间动态跳动【HTML】

[复制链接]
跳转到指定楼层
楼主
katelya 发表于 2024-8-14 11:07 回帖奖励
本帖最后由 katelya 于 2024-8-14 11:52 编辑

前言

此代码适合很多场景,像什么博客、论坛、个人导航页,加上它都是不错的选择,而且样式也挺好看的,接下来话不多说上码

代码

<style>
    #uptime {
        position: fixed; /* 固定定位 */
        bottom: 0; /* 距离底部0 */
        left: 0; /* 距离左侧0 */
        width: 100%; /* 宽度为100% */
        font-family: Arial, sans-serif;
        font-size: 18px;
        color: #333;
        text-align: center; /* 文本居中 */
        padding: 15px;
        background-color: rgba(255, 255, 255, 0.2); /* 背景颜色透明 */
        border-top: 1px solid #ddd; /* 上边框 */
        border-radius: 8px 8px 0 0; /* 上边圆角 */
        box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1); /* 上方阴影 */
    }

    .highlight {
        color: orange; /* 橙色 */
        font-weight: bold; /* 粗体 */
    }
</style>

<div id="uptime">Loading...</div>

<script>
    // 网站建站日期
    const launchDate = new Date('2024-08-14'); // 修改为您的建站日期

    // 计算日期差异
    const calculateUptime = (startDate, endDate) => {
        const diffTime = endDate - startDate; // 时间差,单位毫秒
        const diffSeconds = Math.floor(diffTime / 1000); // 秒数
        const diffMinutes = Math.floor(diffSeconds / 60); // 分钟数
        const diffHours = Math.floor(diffMinutes / 60); // 小时数
        const diffDays = Math.floor(diffHours / 24); // 天数
        const hours = diffHours % 24; // 当前天的小时数
        const minutes = diffMinutes % 60; // 当前小时的分钟数
        const seconds = diffSeconds % 60; // 当前分钟的秒数

        return { diffDays, hours, minutes, seconds };
    };

    // 更新显示的时间
    const updateUptime = () => {
        const currentDate = new Date();
        const { diffDays, hours, minutes, seconds } = calculateUptime(launchDate, currentDate);
        document.getElementById('uptime').innerHTML = 
            `网站已运行 <span class="highlight">${diffDays}</span> 天 <span class="highlight">${hours}</span> 小时 <span class="highlight">${minutes}</span> 分钟 <span class="highlight">${seconds}</span> 秒`;
    };

    // 每秒更新一次显示的时间
    setInterval(updateUptime, 1000);

    // 初始更新
    updateUptime();
</script>

小白看过来(使用方法)

直接把上面的代码放入你网站的index.html/php的footer页脚
还有那个建站日期自己改一下
style可以自行修改是这个文字背后的背景框有颜色、大小、阴影等等
script自己整个复制进去就好了

END

免费评分

参与人数 1吾爱币 +7 热心值 +1 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

沙发
l160962937 发表于 2024-8-19 17:45
感谢分享!
3#
8211059a 发表于 2024-8-21 20:34
尝试过了,非常好用,右键txt打开index.html文件,复制到index.html文件底部即可,保存,替换即可
4#
shuai2051 发表于 2024-8-22 09:53
本帖最后由 shuai2051 于 2024-8-22 09:57 编辑

楼主的代码JS部分使用的是UTC时间,我改了一个北京时间的,可供参考
[JavaScript] 纯文本查看 复制代码
    // 网站建站日期,假设为北京时间
    const launchDate = new Date('2024-08-21T00:00:00+08:00'); // 北京时间建站日期

    // 获取当前时间(自动处理时区为当地时间)
    const getCurrentBeijingTime = () => {
        const now = new Date();
        // 将当前时间转换为UTC,然后再调整为北京时间(UTC+8)
        const beijingOffset = 8 * 60; // 北京时间与UTC的分钟差
        const localOffset = now.getTimezoneOffset(); // 本地时区与UTC的分钟差
        const offsetDifference = beijingOffset + localOffset; // 与北京时间的差异
        return new Date(now.getTime() + offsetDifference * 60000); // 调整后的北京时间
    };

    // 计算日期差异
    const calculateUptime = (startDate, endDate) => {
        const diffTime = endDate - startDate; // 时间差,单位毫秒
        const diffSeconds = Math.floor(diffTime / 1000); // 秒数
        const diffMinutes = Math.floor(diffSeconds / 60); // 分钟数
        const diffHours = Math.floor(diffMinutes / 60); // 小时数
        const diffDays = Math.floor(diffHours / 24); // 天数
        const hours = diffHours % 24; // 当前天的小时数
        const minutes = diffMinutes % 60; // 当前小时的分钟数
        const seconds = diffSeconds % 60; // 当前分钟的秒数

        return { diffDays, hours, minutes, seconds };
    };

    // 更新显示的时间
    const updateUptime = () => {
        const currentDate = getCurrentBeijingTime(); // 获取北京时间
        const { diffDays, hours, minutes, seconds } = calculateUptime(launchDate, currentDate);
        document.getElementById('uptime').innerHTML = 
            `已运行 <span class="highlight">${diffDays}</span> 天 <span class="highlight">${hours}</span> 小时 <span class="highlight">${minutes}</span> 分钟 <span class="highlight">${seconds}</span> 秒`;
    };

    // 每秒更新一次显示的时间
    setInterval(updateUptime, 1000);

    // 初始更新
    updateUptime();
5#
WePojie 发表于 2024-8-23 11:35
谢谢分享,很好用
6#
pxhzai 发表于 2024-9-19 04:51
很棒,我直接丢到ai  然后他帮我加入到网站代码里
预览 https://poe.qq62.cn/
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-9-21 09:52

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表