网站运行时间代码

2021-02-24 PM 24℃ 0条

可以放到footer.php文件

样式一

<span> 本站已运行</span><span id="span_dt_dt"></span><script> /*建站时间*/ function show_date_time() { window.setTimeout("show_date_time()", 1e3); var BirthDay = new Date("2018/03/01"), today = new Date, timeold = today.getTime() - BirthDay.getTime(), msPerDay = 864e5, e_daysold = timeold / msPerDay, daysold = Math.floor(e_daysold), e_hrsold = 24 * (e_daysold - daysold), hrsold = Math.floor(e_hrsold), e_minsold = 60 * (e_hrsold - hrsold), minsold = Math.floor(60 * (e_hrsold - hrsold)), seconds = Math.floor(60 * (e_minsold - minsold)); span_dt_dt.innerHTML = daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒"; } show_date_time();</script>

样式二

当前系统时间<span id="nowTime"></span>
<script type="text/javascript">//获取系统时间
var newDate = '';
getLangDate();//值小于10时,在前面补0
function dateFilter(date){ 
if(date < 10){return "0"+date;
} 
return date;
}
function getLangDate(){ 
var dateObj = new Date(); //表示当前系统时间的Date对象 
var year = dateObj.getFullYear(); //当前系统时间的完整年份值 
var month = dateObj.getMonth()+1; //当前系统时间的月份值 
var date = dateObj.getDate(); //当前系统时间的月份中的日 
var day = dateObj.getDay(); //当前系统时间中的星期值 
var weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; 
var week = weeks[day]; //根据星期值,从数组中获取对应的星期字符串 
var hour = dateObj.getHours(); //当前系统时间的小时值 
var minute = dateObj.getMinutes(); //当前系统时间的分钟值 
var second = dateObj.getSeconds(); //当前系统时间的秒钟值 
var timeValue = "" +((hour >= 12) ? (hour >= 18) ? "晚上" : "下午" : "上午" ); //当前时间属于上午晚上还是下午 
newDate = dateFilter(year)+"年"+dateFilter(month)+"月"+dateFilter(date)+"日 "+" "+dateFilter(hour)+":"+dateFilter(minute)+":"+dateFilter(second); document.getElementById("nowTime").innerHTML = timeValue+"好!当前时间为: "+newDate+" "+week; setTimeout("getLangDate()",1000);
}
</script>
标签: 美化, 运行时间

非特殊说明,本博所有文章均为博主原创。

评论啦~