由于看到一些论坛中有一个现实网站运营时间,我觉得这个功能不错,但是对于wordpress,目前好像没有插件可以实现,只能通过写代码实现了
我现实的是在我的首页最新消息的后面。关于这个功能实现的代码如下
我是将这个代码放在右侧html小工具,也可以贴到footer.php,具体显示位置自己设定即可。
1.显示的是运行的 天/小时/分/秒
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<span id=“timeDate”>载入天数...</span><span id=“times”>载入时分秒...</span>
<script language=“javascript”>
var now = new Date();
function createtime(){
var grt= new Date(“11/25/2013 21:51:00”);//此处修改你的建站时间或者网站上线时间
now.setTime(now.getTime()+250);
days = (now – grt ) / 1000 / 60 / 60 / 24;
dnum = Math.floor(days);
hours = (now – grt ) / 1000 / 60 / 60 – (24 * dnum);
hnum = Math.floor(hours);
if(String(hnum).length ==1 ){hnum = “0” + hnum;}
minutes = (now – grt ) / 1000 /60 – (24 * 60 * dnum) – (60 * hnum);
mnum = Math.floor(minutes);
if(String(mnum).length ==1 ){mnum = “0” + mnum;}
seconds = (now – grt ) / 1000 – (24 * 60 * 60 * dnum) – (60 * 60 * hnum) – (60 * mnum);
snum = Math.round(seconds);
if(String(snum).length ==1 ){snum = “0” + snum;}
document.getElementById(“timeDate”).innerHTML = “本站已安全运行”+dnum+”天”;
document.getElementById(“times”).innerHTML = hnum + “小时” + mnum + “分” + snum + “秒”;
}
setInterval(“createtime()”,250);
</script>
|
2.显示的是运行的 天
1
2
3
4
5
6
7
8
9
10
11
12
|
本站已安全运行了:<span class=“smalltxt”>
<SCRIPT language=javascript>
BirthDay=new Date(“11 25,2013”);
today=new Date();
timeold=(today.getTime()–BirthDay.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
document.write(“<font color=red>”+daysold+“</font>天 !”);
</SCRIPT>
|
3.显示格式:已运行0 年 1 天 0 小时 4 分钟 35 秒
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
<span id=“sitetime”></span>
<script language=javascript>
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()
/* Date.UTC() — 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
year – 作为date对象的年份,为4位年份值
month – 0-11之间的整数,做为date对象的月份
day – 1-31之间的整数,做为date对象的天数
hours – 0(午夜24点)-23之间的整数,做为date对象的小时数
minutes – 0-59之间的整数,做为date对象的分钟数
seconds – 0-59之间的整数,做为date对象的秒数
microseconds – 0-999之间的整数,做为date对象的毫秒数 */
var t1 = Date.UTC(2013,11,25,21,30,20)
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>
|
我的博客采用的是第三种方式显示
本文转载链接:http://www.66at.com/725.html
我就捡了个运行天数的加到底部去了。o(≧∇≦o)
Yes
学习了 😉