显示日期、时间、星期走动的JavaScript代码

pop:网上有不少这样代码。有些有日期、没有星期,有的只有时间,我整合了一下网上的

代码简洁明了,DIV结构。

代码如下:

<script language="javascript">
today=new Date();
var week; var date;
if(today.getDay()==0) week="星期日"
if(today.getDay()==1) week="星期一"
if(today.getDay()==2) week="星期二"
if(today.getDay()==3) week="星期三"
if(today.getDay()==4) week="星期四"
if(today.getDay()==5) week="星期五"
if(today.getDay()==6) week="星期六"
date=(today.getYear())+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日&nbsp;"+today.getHours()+"时"+today.getMinutes()+"分"+today.getSeconds()+"秒&nbsp;"
document.write("<span style='font-size:18px;'>"+date+week+"</span>"); 
</script>

<div id="times">The Time Is Loading…</div>
<script language="javascript" type="text/javascript">setInterval("document.getElementById('times').innerHTML=new Date().toLocaleString()+''.charAt(new Date().getDay());",1000);</script>

<div id="liveclock" style="width:210px;height:20px;font-size:14px;"></div>
<script language=javascript>
function time()
{
var today=new Date()
var week; var date;
if(today.getDay()==0) week="星期日"
if(today.getDay()==1) week="星期一"
if(today.getDay()==2) week="星期二"
if(today.getDay()==3) week="星期三"
if(today.getDay()==4) week="星期四"
if(today.getDay()==5) week="星期五"
if(today.getDay()==6) week="星期六"
date=(today.getYear())+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日&nbsp;"
var hours=today.getHours()
var minutes=today.getMinutes()
var seconds=today.getSeconds()
if(minutes<=9)
minutes="0"+minutes
if(seconds<=9)
seconds="0"+seconds
myclock=date+hours+":"+minutes+":"+seconds+"&nbsp;"+week
if(document.layers){document.layers.liveclock.document.write(myclock)
document.layers.liveclock.document.close()
}else if(document.all)
liveclock.innerHTML=myclock
setTimeout("time()",1000)
}
time();
</script>

Related Posts