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

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

 

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://cdn-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>

 

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

米扑博客稳定运行