米扑科技旗下的多个产品,如米扑主站米扑博客米扑代理米扑财富

需要显示网站运行时间,让客户知道我们公司是非常稳健运行的 

 

JS 计算时间差的年月日时分秒

<div class="runningtime">
    米扑博客稳定运行 <span id="elapseClock"><span class="digit">3013</span>天<span class="digit">21</span>时<span class="digit">58</span>分<span class="digit">21</span>秒</span>
</div>

<script type="text/javascript" src="https://blog.mimvp.com/wp-includes/js/jquery/jquery.js"></script>

<script type="text/javascript">
var isYear = 0;
timeElapse(isYear);
setInterval(function () {
    timeElapse(isYear);
}, 1000);

function timeElapse(isYear) {
    var dtime_start = new Date(2009, 07, 01,00,00,00);
    var dtime_now = Date();
    var dtime_delta = (Date.parse(dtime_now) - Date.parse(dtime_start)) / 1000;

    
    var resDay = Math.floor(dtime_delta / (3600 * 24));

	var resYear = 0;
    if(isYear == 1) {
    	resYear = Math.floor(resDay / 365);
		resDay = resDay % 365;
    }

    // cal hour
    dtime_delta = dtime_delta % (3600 * 24);
    var resHour = Math.floor(dtime_delta / 3600);
    if (resHour < 10) {
        resHour = "0" + resHour
    }

    // cal minute
    dtime_delta = dtime_delta % 3600;
    var resMinute = Math.floor(dtime_delta / 60);
    if (resMinute < 10) {
        resMinute = "0" + resMinute
    }

    // cal second
    dtime_delta = dtime_delta % 60;
    if (dtime_delta < 10) {
        dtime_delta = "0" + dtime_delta
    }

    var result = '' + resDay + '' + resHour + '' + resMinute + '' + dtime_delta + "秒";
    if(isYear == 1) {
    	result = '' + resYear + '' + resDay + '' + resHour + '' + resMinute + '' + dtime_delta + "秒";
    }
    jQuery("#elapseClock").html(result)
}
</script>

 

运行效果见米扑博客,或如下:

米扑博客稳定运行

 

 

参考推荐:

JS 日期格式与时间戳转换

JS 手机号、电话号码正则表达式

JS 正则表达式验证数字

JS 去除字符串中的空格

JS javascript:void(0) 真正含义

Javascript 函数参数默认值的设置

js 函数设置默认参数值的3种方法

JS检测移动端自适应屏幕大小

Javascript 常用功能的实现与封装库

JavaScript学习笔记(一)——JS基础知识介绍