以前自己写的3段JavaScript脚本,今天偶然翻到,贴出来给大家分享。 (比较实用,放在论坛或者博客都可以)
倒计时(只适用于对同一月内某一天的倒计时,跨月无效) var calendar = new Date(); var date = 30 - calendar.getDate(); if (date > 0) document.write("<font style='color:#0aa4ec; font-size:9pt; font-family: Comic Sans MS, Arial, Helvetica, sans-serif;'>","5月30日倒计时中...... 还有" + "<font color=737373>",date,"</font>" + "天","</font>"); if (date == 0) document.write("<font style='color:#0aa4ec; font-size:9pt; font-family: Comic Sans MS, Arial, Helvetica, sans-serif;'>","今天是5月30日!","</font>");
显示希腊时间(按固定时差6小时计算,未考虑夏令时的自动调整) function GreekClock() {if (!document.layers && !document.all) return; var runTime = new Date(); var hours = runTime.getHours()-6; var minutes = runTime.getMinutes(); var seconds = runTime.getSeconds(); var dn = "AM"; if (hours < 0) {hours = hours + 24;} if (hours >= 12) {dn = 'PM';hours = hours - 12;} if (hours == 0 && dn == 'PM') {hours = 12;} if (minutes <= 9) {minutes = '0' + minutes;} if (seconds <= 9) {seconds = '0' + seconds;} movingtime = "<font color=#70bafe style='font-size:8.5pt;font-family:verdana'>" + hours + ":" + minutes + ":" + seconds + " " + dn + "</font>"; if (document.layers) {document.layers.Myclock.document.write(movingtime); document.layers.Myclock.document.close();}else if (document.all) {Myclock.innerHTML = movingtime;} setTimeout("GreekClock()", 1000);}window.onload = GreekClock;
英文显示星期、日期 <script> today = new Date(); function initArray(){ this.length=initArray.arguments.length for(var i=0;i<this.length;i++) this[i+1]=initArray.arguments[ i ] } var d = new initArray( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); var m = new initArray( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); var n=today.getDate(); var orn = 'th'; { if (n == 1 || n== 11 || n == 21 || n == 31) {orn = 'st';} else if (n == 2 || n== 12 || n == 22) {orn = 'nd';} else if (n == 3 || n== 13 || n == 23) {orn = 'rd';} } document.write( m[today.getMonth()+1]," ", today.getDate(),orn,", ", today.getYear()," ", d[today.getDay()+1]); </script>
看完代码感慨:原来现在的我已经退化了………………[Edit on 2008-11-01 22:49:16 By Jasmine] |