在网页中调用当前日期代码
怎么在网站的header.htm中插入一个能够显示当前时间的代码,我的网站是用DiscuzX2.5做的...
怎么在网站的header.htm 中插入一个能够显示当前时间的代码,我的网站是用DiscuzX2.5做的
展开
2个回答
展开全部
<span id="time"></span>
<script>
var weekdays = ["天","一","二","三","四","五","六"];
/*
1.显示当前时间
设置一秒后再调用 getTimes()
2.显示当前时间
设置一秒后再调用 getTimes()
*/
window.onload = getTimes;
function getTimes(){
var d = new Date();
var yy = d.getFullYear();
var mo = d.getMonth()+ 1;
var dd = d.getDate();
var hh = d.getHours();
var mi = d.getMinutes();
var ss = d.getSeconds();
if (mo<10)
{
mo = '0' + mo;
}
if (dd<10)
{
dd = '0' + dd;
}
if (hh<10)
{
hh = '0' + hh;
}
if (mi<10)
{
mi = '0' + mi;
}
if (ss<10)
{
ss = '0' + ss;
}
var str =yy + "-" + mo + "-" + dd + " 星期" + weekdays[d.getDay()];
str += " " + hh + ":" + mi + ":" + ss;
document.getElementById("time").innerHTML = str;
setTimeout("getTimes()",1000);
}
function getWeekDay(day){
switch(day)
{
case 0:
return "天"
case 1:
return "一"
case 2:
return "二"
case 3:
return "三"
case 4:
return "四"
case 5:
return "五"
case 6:
return "六"
}
}
</script>
<script>
var weekdays = ["天","一","二","三","四","五","六"];
/*
1.显示当前时间
设置一秒后再调用 getTimes()
2.显示当前时间
设置一秒后再调用 getTimes()
*/
window.onload = getTimes;
function getTimes(){
var d = new Date();
var yy = d.getFullYear();
var mo = d.getMonth()+ 1;
var dd = d.getDate();
var hh = d.getHours();
var mi = d.getMinutes();
var ss = d.getSeconds();
if (mo<10)
{
mo = '0' + mo;
}
if (dd<10)
{
dd = '0' + dd;
}
if (hh<10)
{
hh = '0' + hh;
}
if (mi<10)
{
mi = '0' + mi;
}
if (ss<10)
{
ss = '0' + ss;
}
var str =yy + "-" + mo + "-" + dd + " 星期" + weekdays[d.getDay()];
str += " " + hh + ":" + mi + ":" + ss;
document.getElementById("time").innerHTML = str;
setTimeout("getTimes()",1000);
}
function getWeekDay(day){
switch(day)
{
case 0:
return "天"
case 1:
return "一"
case 2:
return "二"
case 3:
return "三"
case 4:
return "四"
case 5:
return "五"
case 6:
return "六"
}
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询