六祎-网站运行时间代码(准确到秒)

 

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(2019,8,27,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()
将上面js代码中第15行位置改为建站时间

var t1 = Date.UTC(2019,8,27,08,19,00)
将下列代码放在你想要显示网站运行时间的位置即可


<p>博客已稳定运行<span id="sitetime" ></span></p>



 

全部评论

相关推荐

手撕没做出来是不是一定挂
Chrispp3:不会,写出来也不一定过
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-26 15:46
已编辑
字节国际 电商后端 24k-35k
点赞 评论 收藏
分享
10-09 09:39
门头沟学院 C++
HHHHaos:这也太虚了,工资就一半是真的
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务