标签:var lang interval turn 自己 timestamp 博客 int mat
<p id="run_time" style="color: rgb(0,181,173);font-size: large;font-weight: bold">
<script>
function secondToDate(second) {
if (!second) {
return 0;
}
var time = new Array(0, 0, 0, 0, 0);
if (second >= 365 * 24 * 3600) {
time[0] = parseInt(second / (365 * 24 * 3600));
second %= 365 * 24 * 3600;
}
if (second >= 24 * 3600) {
time[1] = parseInt(second / (24 * 3600));
second %= 24 * 3600;
}
if (second >= 3600) {
time[2] = parseInt(second / 3600);
second %= 3600;
}
if (second >= 60) {
time[3] = parseInt(second / 60);
second %= 60;
}
if (second > 0) {
time[4] = second;
}
return time;
}
function setTime() {
/*此处为网站的创建时间*/
var create_time = Math.round(new Date(Date.UTC(2019, 07, 05, 18, 01, 01)).getTime() / 1000);
var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
currentTime = secondToDate((timestamp - create_time));
currentTimeHtml = ‘该博客网已苟活:‘ + currentTime[0] + ‘年‘ + currentTime[1] + ‘天‘
+ currentTime[2] + ‘时‘ + currentTime[3] + ‘分‘ + currentTime[4]
+ ‘秒‘;
document.getElementById("run_time").innerHTML = currentTimeHtml;
}
setInterval(setTime, 1000);
</script>
注:上述js需要自己去修改网站的创建时间,和内容,代码中有注释,直接修改即可
标签:var lang interval turn 自己 timestamp 博客 int mat
原文地址:https://www.cnblogs.com/zq98/p/15027906.html