显示日期、时间、星期走动的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>

This entry was posted in Technology and tagged , , . Bookmark the permalink. 12,516 views

Related Posts

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

  1. 网站seo says:

    这是个好东东,一般网站都需要这个脚本。
    [reply=pop,2010-06-01 09:46 PM]呵呵,懂JAVA的话都可以自己写一个,只是我没这个水平,只能改别人的东西。[/reply]

  2. 小秦 says:

    帮博主更正一下,上面的代码是javascript,而不是java.
    这是两种不同的语言,请注意区分一下.

    • pop says:

      谢谢,马上更正了。我也是为了简单好记,所以没有去探究这个东西。概念比较模糊。

Leave a Reply

Your email address will not be published. Required fields are marked *