Wednesday, October 10, 2007, 09:34 AM - Scripts
Posted by Administrator
The original code is:Posted by Administrator
function doClock(){ // By Paul Davis - www.kaosweaver.com
var t=new Date(),a=doClock.arguments,str="",i,a1,lang="1";
var month=new Array('January','Jan', 'February','Feb', 'March','Mar', 'April','Apr', 'May','May', 'June','Jun', 'July','Jul', 'August','Aug', 'September','Sep', 'October','Oct', 'November','Nov', 'December','Dec');
var tday= new Array('Sunday','Sun','Monday','Mon', 'Tuesday','Tue', 'Wednesday','Wed','Thursday','Thr','Friday','Fri','Saturday','Sat');
for(i=0;i<a.length;i++) {a1=a[ i ].charAt(1);switch (a[ i ].charAt(0)) {
case "M":if ((Number(a1)==3) && ((t.getMonth()+1)<10)) str+="0";
str+=(Number(a1)>1)?t.getMonth()+1:month[t.getMonth()*2+Number(a1)];break;
case "D": if ((Number(a1)==1) && (t.getDate()<10)) str+="0";str+=t.getDate();break;
case "Y": str+=(a1=='0')?t.getFullYear():t.getFullYear().toString().substring(2);break;
case "W":str+=tday[t.getDay()*2+Number(a1)];break; default: str+=unescape(a[ i ]);}}return str;
}
With this code in the page:
document.write(doClock("W0","%20","M3","/","D1","/","Y0"));
The library form of the script is:
var dD= {
addEvent: function(obj,evt, fn) {if (obj.addEventListener) {obj.addEventListener(evt, fn, false);
} else if (obj.attachEvent) {obj.attachEvent('on'+evt, fn);} else {obj['on'+evt]=fn;}},
m:function() {dD.mA=arguments;},d:function() {dD.dA=arguments;},p:function() {dD.fA=arguments;},
$:function() {str="";t=new Date();a=dD.fA;for(i=0;i<a.length-1;i++) {a1=a[ i ].charAt(1);
switch (a[ i ].charAt(0)) {case "M":if ((Number(a1)==3) && ((t.getMonth()+1)<10))str+="0";
str+=(Number(a1)>1)?t.getMonth()+1:dD.mA[t.getMonth()*2+Number(a1)];break;case "D":
if ((Number(a1)==1) && (t.getDate()<10)) str+="0";str+=t.getDate();break;case "Y":
str+=(a1=='0')?t.getFullYear():t.getFullYear().toString().substring(2);break;case "W":
str+=dD.dA[t.getDay()*2+Number(a1)];break;default:str+=unescape(a[ i ]);}}
tbo=document.getElementById(a[a.length-1]);tbo.appendChild(document.createTextNode(str))},
mA:[],dA:[],fA:[]
}
dD.m('January','Jan', 'February','Feb', 'March','Mar', 'April','Apr', 'May','May', 'June','Jun', 'July','Jul', 'August','Aug', 'September','Sep', 'October','Oct', 'November','Nov', 'December','Dec')
dD.d('Sunday','Sun','Monday','Mon', 'Tuesday','Tue', 'Wednesday','Wed','Thursday','Thr','Friday','Fri','Saturday','Sat')
dD.p("M0"," ","M1"," ","W0"," ","W1"," ","Y1","displayDate")
dD.addEvent(window, "load", dD.$, false);
With the only thing in the body of the page:
<div id="displayDate"></div>
We incorporated the addEvent function from the gO global object library, this can be omitted if you've already got the global object library included on the page. As the code string shows, you can swap out the language by simply replacing the language of choice in place of the month and day names. The codes in the call line (dD.p function call) are:
"W0"=Day of Week - Full
"W1"=Day of Week - Short
"M2"=Month - Number
"M3"=Month - 2 Digit Number
"M0"=Month - Full
"M1"=Month - Short
"D0"=Date
"D1"=Date - 2 Digit
"Y0"=Year - Full
"Y1"=Year - Short
The last argument on the function is the place (by ID) where you want the date to be displayed. (hence the DIV with the ID displayDate)




( 3 / 574 )

Calendar
