JS 计算时间差的年月日时分秒
589 views
1
米扑科技旗下的多个产品,如米扑主站、米扑博客、米扑代理、米扑财富等
需要显示网站运行时间,让客户知道我们公司是非常稳健运行的
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>
运行效果见米扑博客,或如下:
米扑博客稳定运行
参考推荐:
版权所有: 本文系米扑博客原创、转载、摘录,或修订后发表,最后更新于 2019-12-15 23:31:54
侵权处理: 本个人博客,不盈利,若侵犯了您的作品权,请联系博主删除,莫恶意,索钱财,感谢!
转载注明: JS 计算时间差的年月日时分秒 (米扑博客)
这个代码有点意思,回头也给自己的网站加一个。