很多个人网站博客喜欢在底部加入网站运行时间统计,显得逼格特别上档次,今天技术小编就分享下,一个购买了织梦模板的用户,寻求这样一个代码加上运行时间代码。
查看了网上很多教程,貌似都只能精确到天,今天我们秀站网技术小编分享的代码是运行时间精确到年月日时分秒。
网站运行时间代码:
<script>
function siteTime(){
window.setTimeout("siteTime()", 1000);
var seconds = 1000
var minutes = seconds * 60
var hours = minutes * 60
var days = hours * 24
var years = days * 365
var today = new Date()
var todayYear = today.getFullYear()
var todayMonth = today.getMonth()
var todayDate = today.getDate()
var todayHour = today.getHours()
var todayMinute = today.getMinutes()
var todaySecond = today.getSeconds()
var t1 = Date.UTC(2018,12,29,08,19,00)
var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond)
var diff = t2-t1
var diffYears = Math.floor(diff/years)
var diffDays = Math.floor((diff/days)-diffYears*365)
var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours)
var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes)
var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds)
document.getElementById("sitetime").innerHTML=""+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒"
}
siteTime()
</script>
将上面js代码中:var t1 = Date.UTC(2018,12,29,08,19,00) 改为你网站的建站时间,如时间是:2018年12月29号08点19分00秒。
2)将下列代码添加到你网站htm(模板文件)代码中,放在你想要显示网站运行时间的位置即可,可以是网站底部、侧边栏等。
PS:其中style="color:#096"是网站运行时间的颜色,可以改为其他颜色,也可以删掉。
<p>深山博客运行<span id="sitetime" style="color:#096"></span></p>
3.网站运行时间代码添加完成之后的效果如下图:
转载请注明来源网址:https://www.mubanyun.com/news/1775.html
发表评论
评论列表(条)