统计
  • 文章总数:1580 篇
  • 评论总数:350 条
  • 分类总数:37 个
  • 最后更新:4月26日

Typecho 博客网站运行时间 网站倒计时 运行天数代码

本文阅读 1 分钟
首页 typecho 正文
<script>
function secondToDate(second) {
    if (!second) {
        return 0;
    }
    var time = new Array(0, 0, 0, 0, 0);
    if (second >= 365 * 24 * 3600) {
        time[0] = parseInt(second / (365 * 24 * 3600));
        second %= 365 * 24 * 3600;
    }
    if (second >= 24 * 3600) {
        time[1] = parseInt(second / (24 * 3600));
        second %= 24 * 3600;
    }
    if (second >= 3600) {
        time[2] = parseInt(second / 3600);
        second %= 3600;
    }
    if (second >= 60) {
        time[3] = parseInt(second / 60);
        second %= 60;
    }
    if (second > 0) {
        time[4] = second;
    }
    return time;
}
</script>
<script type="text/javascript" language="javascript">
function setTime() {
    // 博客创建时间秒数,时间格式中,月比较特殊,是从0开始的,所以想要显示5月,得写4才行,如下
    var create_time = Math.round(new Date(Date.UTC(2013, 4, 22, 0, 0, 0))
            .getTime() / 1000);
    // 当前时间秒数,增加时区的差异
    var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
    currentTime = secondToDate((timestamp - create_time));
    currentTimeHtml = currentTime[0] + '年' + currentTime[1] + '天'
            + currentTime[2] + '时' + currentTime[3] + '分' + currentTime[4]
            + '秒';
    document.getElementById("htmer_time").innerHTML = currentTimeHtml;
}
setInterval(setTime, 1000);
</script>
网站运行:<span id="htmer_time" style="color: red;"></span>

把代码放在博客底部的位置就可以啦

本文来自投稿,不代表本站立场,如若转载,请注明出处:
-- 展开阅读全文 --
Typecho Plugins 站点地图 sitemap.xml 生成器
« 上一篇 08-09
免费领取李现七夕微信红包封面3个月方法分享
下一篇 » 08-16