岁月无声 2006-10-24 22:41
经典时间代码集锦
<P>实时走动的数字时钟 </P>
<P><script><BR>function tick() {<BR>var hours, minutes, seconds, xfile;<BR>var intHours, intMinutes, intSeconds;<BR>var today;<BR>today = new Date();<BR>intHours = today.getHours();<BR>intMinutes = today.getMinutes();<BR>intSeconds = today.getSeconds();<BR>if (intHours == 0) {<BR>hours = "12:";<BR>xfile = "午夜";<BR>} else if (intHours < 12) { <BR>hours = intHours+":";<BR>xfile = "上午";<BR>} else if (intHours == 12) {<BR>hours = "12:";<BR>xfile = "正午";<BR>} else {<BR>intHours = intHours - 12<BR>hours = intHours + ":";<BR>xfile = "下午";<BR>}<BR>if (intMinutes < 10) {<BR>minutes = "0"+intMinutes+":";<BR>} else {<BR>minutes = intMinutes+":";<BR>}<BR>if (intSeconds < 10) {<BR>seconds = "0"+intSeconds+" ";<BR>} else {<BR>seconds = intSeconds+" ";<BR>} <BR>timeString = xfile+hours+minutes+seconds;<BR>Clock.innerHTML = timeString;<BR>window.setTimeout("tick();", 100);<BR>}<BR>window.onload = tick;<BR></script></P>
<P>第二步.将下面的代码加入html文件任意需要的地方</P>
<P><div id="Clock" align="center" style="font-size: 20; color:#000000"></div></P>
<P>你可以自行更改样式!</P>
<P> </P>
<P>显示年月日格式的时间代码 </P>
<P><script language=javascript><BR>today=new Date();<BR>function initArray(){<BR>this.length=initArray.arguments.length<BR>for(var i=0;i<this.length;i++)<BR>this[i+1]=initArray.arguments[i] }<BR>var d=new initArray(<BR>"星期日",<BR>"星期一",<BR>"星期二",<BR>"星期三",<BR>"星期四",<BR>"星期五",<BR>"星期六");<BR>document.write(<BR>"<font color=##000000 style=font-size:9pt;font-family: 宋体> ",<BR>today.getYear(),"年",<BR>today.getMonth()+1,"月",<BR>today.getDate(),"日",<BR>d[today.getDay()+1],<BR>"</font>" ); </P>
<P> </P>
<P>显示日期,星期,时间格式的代码 </P>
<P><script language="javascript"> <BR><!---<BR>today=new Date();<BR>var hours = today.getHours();<BR>var minutes = today.getMinutes();<BR>var seconds = today.getSeconds();<BR>var timevalue = "<FONT COLOR=black>" + ((hours >12) ? hours -12 :hours); timevalue += ((minutes < 10) ? "<BLINK></P>
<P><FONT COLOR=black>:</FONT></BLINK>0" : "<BLINK><FONT COLOR=black>:</FONT></BLINK>") + minutes+"</FONT></FONT>";</P>
<P>timevalue += (hours >= 12) ? "<FONT COLOR=blue><I><B>pm</B></I></FONT>" : "<FONT COLOR=blue><B><I>am</I></B></FONT>";<BR>function initArray(){<BR>this.length=initArray.arguments.length<BR>for(var i=0;i<this.length;i++)<BR>this[i+1]=initArray.arguments[i] }<BR>var d=new initArray("<font color=RED>星期日","<font color=black>星期一","<font color=black>星期二","<font color=black>星期</P>
<P>三","<font color=black>星期四","<font color=black>星期五","<font color=red>星期六"); document.write</P>
<P>("<font color=black>",today.getYear(),"<font color=black>年","<font color=black>",today.getMonth()+1,"<font color=black></P>
<P>月","<font color=black>",today.getDate(),"<font color=black>日 </FONT>",d[today.getDay()+1]," ",timevalue); //--><BR></script> </P>
<P> </P>
<P>显示来访者的停留时间 </P>
<P><script language="javascript"><BR>var ap_name = navigator.appName;<BR>var ap_vinfo = navigator.appVersion;<BR>var ap_ver = parseFloat(ap_vinfo.substring(0,ap_vinfo.indexOf(()));</P>
<P>var time_start = new Date();<BR>var clock_start = time_start.getTime();<BR>var dl_ok=false;</P>
<P>function init ()<BR>{<BR>if(ap_name=="Netscape" && ap_ver>=3.0)<BR>dl_ok=true; <BR>return true;<BR>}</P>
<P>function get_time_spent ()<BR>{ <BR>var time_now = new Date();<BR>return((time_now.getTime() - clock_start)/1000); <BR>}</P>
<P>function show_secs () // show the time user spent on the side<BR>{ <BR>var i_total_secs = Math.round(get_time_spent()); <BR>var i_secs_spent = i_total_secs % 60;<BR>var i_mins_spent = Math.round((i_total_secs-30)/60); <BR>var s_secs_spent = "" + ((i_secs_spent>9) ? i_secs_spent : "0" + i_secs_spent);<BR>var s_mins_spent = "" + ((i_mins_spent>9) ? i_mins_spent : "0" + i_mins_spent);<BR>document.fm0.time_spent.value = s_mins_spent + ":" + s_secs_spent;<BR>window.setTimeout(show_secs(),1000); <BR>}</P>
<P>// --><BR></script><BR><FORM name="fm0" onSubmit="0"><FONT COLOR="#6060FF">停留时间:<BR></FONT><INPUT type="text" name="time_spent" size=7 onFocus="this.blur()"></FORM></P>
<P>第二步:在你主页源文件<body>中加入下面代码的兰色部分</P>
<P><BODY onLoad="init(); window.setTimeout(show_secs(),1);"></P>
<P> </P>
<P>显示当前日期与时间的格式 </P>
<P><script language="javascript"><BR><!--<BR>now = new Date()<BR>hour = now.getHours()<BR>if (hour < 12) {<BR>document.write("现在是: " + now.toLocaleString())<BR>} else if (hour < 18){<BR>document.write("现在是: " + now.toLocaleString())<BR>} else if (hour >= 18) {<BR>document.write("现在是: " + now.toLocaleString())<BR>}<BR>// --></script></P>
<P> </P>
<P>浏览器状态栏显示的时钟 <BR><BODY onLoad="run(); timerONE=window.setTimeout"></BODY><BR><SCRIPT LANGUAGE="javascript"><BR><!-- Hide<BR>timeID = null;<BR>timeRunning = false;<BR>function stop () {<BR>if(timeRunning)<BR>clearTimeout(timeID);<BR>timeRunning = false;<BR>}<BR>function time () {<BR>tick = new Date();<BR>hours = tick.getHours();<BR>minutes = tick.getMinutes();<BR>seconds = tick.getSeconds();<BR>day = tick.getDay();<BR>month = tick.getMonth();<BR>date = tick.getDate();<BR>year = tick.getYear();<BR>current = "" + ((hours >12) ? hours -12 :hours)<BR>current += ((minutes < 10) ? ":0" : ":") + minutes<BR>current += ((seconds < 10) ? ":0" : ":") + seconds<BR>current += (hours >= 12) ? " P.M." : " A.M."<BR>if(day==0){var weekday = " 星期日"}<BR>if(day==1){var weekday = " 星期一"}<BR>if(day==2){var weekday = " 星期二"}<BR>if(day==3){var weekday = " 星期三"}<BR>if(day==4){var weekday = " 星期四"}<BR>if(day==5){var weekday = " 星期五"}<BR>if(day==6){var weekday = " 星期六"}<BR>current +=(weekday)<BR>window.status=current;<BR>timeID = setTimeout("time()",1000);<BR>timeRunning = true;<BR>}<BR>function run(){<BR>stop();<BR>time();<BR>}</P>
<P>//--><BR></SCRIPT></P>
<P> </P>
<P>显示最后更新时间代码 </P>
<P><SCRIPT language=javascript><BR><!--hide script from old browsers<BR>document.write("最后更新时间: " + document.lastModified + "")<BR>// end hiding --><BR></SCRIPT></P>
<P>实时走动的数字时钟 <BR><script><BR>function tick() {<BR>var hours, minutes, seconds, xfile;<BR>var intHours, intMinutes, intSeconds;<BR>var today;<BR>today = new Date();<BR>intHours = today.getHours();<BR>intMinutes = today.getMinutes();<BR>intSeconds = today.getSeconds();<BR>if (intHours == 0) {<BR>hours = "12:";<BR>xfile = "午夜";<BR>} else if (intHours < 12) { <BR>hours = intHours+":";<BR>xfile = "上午";<BR>} else if (intHours == 12) {<BR>hours = "12:";<BR>xfile = "正午";<BR>} else {<BR>intHours = intHours - 12<BR>hours = intHours + ":";<BR>xfile = "下午";<BR>}<BR>if (intMinutes < 10) {<BR>minutes = "0"+intMinutes+":";<BR>} else {<BR>minutes = intMinutes+":";<BR>}<BR>if (intSeconds < 10) {<BR>seconds = "0"+intSeconds+" ";<BR>} else {<BR>seconds = intSeconds+" ";<BR>} <BR>timeString = xfile+hours+minutes+seconds;<BR>Clock.innerHTML = timeString;<BR>window.setTimeout("tick();", 100);<BR>}<BR>window.onload = tick;<BR></script></P>
<P><div id="Clock" style="font-size: 20; color:#000000"></div></P>
<P> </P>
<P>根据不同的时间显示不同的问候语 <BR>方法:在主页中你需要的地方加入以下代码:</P>
<P><script language="LiveScript"><BR>now = new Date(),hour = now.getHours()<BR>if(hour < 6){document.write("明天不用上班了吗?")}<BR>else if (hour < 8){document.write("全新的一天!")}<BR>else if (hour < 12){document.write("早安!")}<BR>else if (hour < 14){document.write("外面太阳大吗?")}<BR>else if (hour < 18){document.write("午安!")}<BR>else if (hour < 22){document.write("晚上好!")}<BR>else if (hour < 24){document.write("夜深了! 要注意身体呀! 祝你做个好梦!")}<BR>// --><BR></script></P>
<P>说明,可以自行修改出更好更多的问候语!</P>
<P> </P>
<P>一个很酷的透明时钟代码 <BR>方法:在页面中你需要的地方加入下面的代码</P>
<P><STYLE type=text/css><BR>BODY {COLOR: #000000; FONT-FAMILY: "宋体"; FONT-SIZE: 9pt; LINE-HEIGHT: 13pt}<BR>TD {COLOR: #000000; FONT-FAMILY: "宋体"; FONT-SIZE: 9pt; LINE-HEIGHT: 13pt}<BR>A:visited {COLOR: #000080;text-decoration:none}<BR>a:link { text-decoration:none }<BR>a:hover { text-decoration:underline }<BR>.f12 {font-size:12px;}<BR>.f13 {font-size:14.9px; LINE-HEIGHT: 120%}<BR>.f24 {font-size:24px;LINE-HEIGHT: 120%}<BR>.f14 {font-size:14.9px; LINE-HEIGHT: 170%}<BR></STYLE><BR><script LANGUAGE="javascript"><BR>Zp=670;H=....;H=H.split();M=.....;M=M.split();S=......;S=S.split();Yp=0;Xp=0;Yb=8;Xb=8;d_=12;</P>
<P>ns=(document.layers)?1:0;fCol=222222;sCol=ff0000;mCol=0000ee;hCol=green;if (ns){dgts=1 2 3 4 5 6 7 8 9 10 11 12;</P>
<P>dgts=dgts.split( );for (i=0;i<d_;i++){document.write(<layer name=nsDigits+i+ top=0 left=0 height=30 width=30></P>
<P><center><font face=Arial,Verdana size=1 color=+fCol+>+dgts[i]+</font></center></layer>);}for (i=0;i<M.length;i++)</P>
<P>{document.write(<layer name=ny+i+ top=0 left=0 bgcolor=+mCol+ clip="0,0,2,2"></layer>);}for (i=0;i<H.length;i++)</P>
<P>{document.write(<layer name=nz+i+ top=0 left=0 bgcolor=+hCol+ clip="0,0,2,2"></layer>);}for (i=0;i<S.length;i++)</P>
<P>{document.write(<layer name=nx+i+ top=0 left=0 bgcolor=+sCol+ clip="0,0,2,2"></layer>);}}else{document.write(</P>
<P><div style="position:absolute;top:0px;left:0px"><div style="position:relative">);for (i=1;i<d_+1;i++){document.write</P>
<P>(<div id="ieDigits" style="position:absolute;top:0px;left:0px;width:30px;height:30px;font-family:Arial,Verdana;font-size:</P>
<P>10px;color:+fCol+;text-align:center;padding-top:10px">+i+</div>);}document.write(</div></div>);document.write</P>
<P>(<div style="position:absolute;top:0px;left:0px"><div style="position:relative">);for (i=0;i<M.length;i++){document.write</P>
<P>(<div id=y style="position:absolute;width:2px;height:2px;font-size:2px;background:+mCol+"></div>);}document.write(</div></P>
<P></div>);document.write(</div></div>);document.write(<div style="position:absolute;top:0px;left:0px"></P>
<P><div style="position:relative">);for (i=0;i<H.length;i++){document.write</P>
<P>(<div id=z style="position:absolute;width:2px;height:2px;font-size:2px;background:+hCol+"></div>);}document.write(</div></P>
<P></div>);document.write(<div style="position:absolute;top:0px;left:0px"><div style="position:relative">);for (i=0;i</P>
<P><S.length;i++){document.write(<div id=x style="position:absolute;width:2px;height:2px;font-size:2px;background:+sCol+"></P>
<P></div>);}document.write(</div></div>);}function clock(){time=new Date ();secs=time.getSeconds();sec=-1.57+Math.PI*secs/</P>
<P>30;mins=time.getMinutes();min=-1.57+Math.PI*mins/30;hr=time.getHours();hrs=-1.57+Math.PI*hr/6+Math.PI*parseInt(time.getMinutes</P>
<P>())/360;if (ns){Yp=window.pageYOffset+window.innerHeight-60;Xp=80;}else</P>
<P>{Yp=document.body.scrollTop+window.document.body.clientHeight-60;Xp=document.body.scrollLeft+60;}if (ns){for (i=0;i<d_;++i)</P>
<P>{document.layers["nsDigits"+i].top=Yp-5+40*Math.sin(-0.49+d_+i/1.9);document.layers["nsDigits"+i].left=Xp-15+40*Math.cos(-0.49</P>
<P>+d_+i/1.9);}for (i=0;i<S.length;i++){document.layers["nx"+i].top=Yp+i*Yb*Math.sin(sec);document.layers</P>
<P>["nx"+i].left=Xp+i*Xb*Math.cos(sec);}for (i=0;i<M.length;i++){document.layers["ny"+i].top=Yp+i*Yb*Math.sin(min);document.layers</P>
<P>["ny"+i].left=Xp+i*Xb*Math.cos(min);}for (i=0;i<H.length;i++){document.layers["nz"+i].top=Yp+i*Yb*Math.sin(hrs);document.layers</P>
<P>["nz"+i].left=Xp+i*Xb*Math.cos(hrs);}}else{for (i=0;i<d_;++i){ieDigits[i].style.pixelTop=Yp-15+40*Math.sin(-0.49+d_+i/</P>
<P>1.9);ieDigits[i].style.pixelLeft=Xp-14+40*Math.cos(-0.49+d_+i/1.9)+Zp;}for (i=0;i<S.length;i++){x</P>
<P>[i].style.pixelTop=Yp+i*Yb*Math.sin(sec);x[i].style.pixelLeft=Xp+i*Xb*Math.cos(sec)+Zp;}for (i=0;i<M.length;i++){y</P>
<P>[i].style.pixelTop=Yp+i*Yb*Math.sin(min);y[i].style.pixelLeft=Xp+i*Xb*Math.cos(min)+Zp;}for (i=0;i<H.length;i++){z</P>
<P>[i].style.pixelTop=Yp+i*Yb*Math.sin(hrs);z[i].style.pixelLeft=Xp+i*Xb*Math.cos(hrs)+Zp;}}setTimeout(clock(), 50);}</P>
<P><BR>if (document.layers || document.all) {window.onload=clock;}<BR>window.onload=clock;<BR></script></P>