显示客户端日期和时间的当前状态

分享于 

2分钟阅读

Web开发

  繁體 雙語

介绍

我向你展示了一个简单的函数集,用来显示你的网页上客户端和时间的日期。

<script language="JavaScript" type=text/JavaScript>var dayarray=new Array ("Sunday","Monday","Tuesday","Wednesday",
 "Thursday","Friday","Saturday")var montharray=new Array("January","February","March","April","May","June",
 "July","August","September","October","November","December")function getthedate(){var mydate=new Date()var year=mydate.getYear()if (year <1000)
year+=1900var day=mydate.getDay()var month=mydate.getMonth()var daym=mydate.getDate()if (daym<10)
daym="0"+daymvar hours=mydate.getHours()var minutes=mydate.getMinutes()var seconds=mydate.getSeconds()var dn=""if (hours>=12)
dn=""if (hours>12){
hours=hours-12
}if (hours==0)
hours=12if (minutes<=9)
minutes="0"+minutesif (seconds<=9)
seconds="0"+seconds//Hire change font sizevar cdate=" <small> <font color='ffffff' face='Arial'>" +dayarray[day]
 +","+daym+""+montharray[month]+","+year
 +""+hours+":"+minutes+":"+seconds+""+dn
 +" </small>"if (document.all)
document.all.clock.innerHTML=cdateelseif (document.getElementById)
document.getElementById("clock").innerHTML=cdateelsedocument.write(cdate)
}if (!document.all&&!document.getElementById)
getthedate()function goforit(){if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}
</script>
<SPAN id=clock></SPAN>

在网页中使用这里脚本,只需将上面的脚本包含在其中,然后在 <正文> 标记。例如:

<bodyleftMargin=0 topMargin=0 onload=goforit() marginwidth="0"marginheight="0">

很简单,用吧。


时间  disp  日期  Clients  
相关文章