zoukankan      html  css  js  c++  java
  • 给网站添加运行时间的JavaScript完整代码

    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;
    }
    function setTime() {
    var create_time = Math.round(new Date(Date.UTC(2018, 05, 01, 01, 01, 01)).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);

    然后在需要引用的地方加上如下代码就行了

    <p id="htmer_time" style="color:#F13F3F;font-size:14px;">

    <script type="text/javascript" src="JavaScript代码地址"></script>

    查看效果:每天进步网  在网站的页脚

    给网站添加根据当前用户的ip地址显示用户的省份市网络

  • 相关阅读:
    student
    super
    java 浮点数
    视图
    日期转换函数
    左外连接,右外连接,全外连接,自然连接,自连接区别
    Python中sys.argv[ ]的用法
    0 Scala
    统计字符串字符个数
    3个链表排序整合到一起
  • 原文地址:https://www.cnblogs.com/xinlvtian/p/9635247.html
Copyright © 2011-2022 走看看