张戈博主分享的一段显示网站时间天,月,日,计时的一段代码。这里分享给大家。也可以详情百度搜索张戈博客搜索自行查找。
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 40 41 42 43 44
| <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;
}
</script>
<script type ="text/javascript" language ="javascript">
function setTime () {
// 博客创建时间秒数,时间格式中,月比较特殊,是从0开始的,所以想要显示5月,得写4才行,如下
var create_time = Math .round(new Date(Date.UTC (2013, 4, 22, 0, 0, 0))
.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 ("htmer_time").innerHTML = currentTimeHtml ;
}
setInterval (setTime , 1000);
</script>
网站运行: <span id ="htmer_time" style ="color: red;"></span > |
注意:
使用方法:将1~43行内容放到网站的footer或header中,然后将44行代码插入统计代码当中或网站合适的位置即可,以上可在我的博客最下面看到具体效果。张戈博客原文链接:https://zhangge.net/3201.html
「梦想一旦被付诸行动,就会变得神圣,如果觉得我的文章对您有用,请帮助本站成长」
共 0 条评论关于"wordpress主题显示年月日的计时代码。附代码详解"
最新评论