如何让网站显示运行时间

  • A+
所属分类:建站
摘要

网站页脚显示运行时间

如何让网站显示运行时间

代码如下:

  1. 网站已运行:<span id="run_time" style="color: black;"></span>  
  2. <script>  
  3. function runTime() {  
  4.     var d = new Date(), str = '';   
  5.     BirthDay = new Date("2019-4-01");  
  6.     today = new Date();  
  7.     timeold = (today.getTime() - BirthDay.getTime());  
  8.     sectimeold = timeold / 1000  
  9.     secondsold = Math.floor(sectimeold);  
  10.     msPerDay = 24 * 60 * 60 * 1000  
  11.     msPerYear = 365 * 24 * 60 * 60 * 1000  
  12.     e_daysold = timeold / msPerDay  
  13.     e_yearsold = timeold / msPerYear  
  14.     daysold = Math.floor(e_daysold);  
  15.     yearsold = Math.floor(e_yearsold);  
  16.     //str = yearsold + "年";  
  17.     str += daysold + "天";  
  18.     str += d.getHours() + '时';  
  19.     str += d.getMinutes() + '分';  
  20.     str += d.getSeconds() + '秒';  
  21.     return str;  
  22. }  
  23.   
  24. setInterval(function () {  
  25.     $('#run_time').html(runTime())  
  26. }, 1000);  
  27. </script>  
  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: