I have two functions that convert an ISO date into whatever date
format I want.  Currently I am using a document.write statement to
write out each date, but I don't want to do that anymore.  I want to
make it unobtrusive, and have jquery find a class selector, and
replace the content.

So, my question is, how can I combine my functions that I already have
created, and have it work with jQuery, so that it can look for a
specific class, which contains the ISO date, and replace that?

Date.prototype.customFormat=function(formatString){
    var
YYYY,YY,MMMM,MMM,MM,M,DDDD,DDD,DD,D,hhh,hh,h,mm,m,ss,s,ampm,dMod,th;
    YY = ((YYYY=this.getFullYear())+"").substr(2,2);
    MM = (M=this.getMonth()+1)<10?('0'+M):M;
    MMM =
(MMMM=["January","February","March","April","May","June","July","August","September","October","November","December"]
[M-1]).substr(0,3);
    DD = (D=this.getDate())<10?('0'+D):D;
    DDD =
(DDDD=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
[this.getDay()]).substr(0,3);
    th=(D>=10&&D<=20)?'th':((dMod=D%10)==1)?'st':(dMod==2)?'nd':
(dMod==3)?'rd':'th';
    formatString =
formatString.replace("#YYYY#",YYYY).replace("#YY#",YY).replace("#MMMM#",MMMM).replace("#MMM#",MMM).replace("#MM#",MM).replace("#M#",M).replace("#DDDD#",DDDD).replace("#DDD#",DDD).replace("#DD#",DD).replace("#D#",D).replace("#th#",th);
     h=(hhh=this.getHours());
    if (h==0) h=24;
    if (h>12) h-=12;
    hh = h<10?('0'+h):h;
    ampm=hhh<12?'am':'pm';
    mm=(m=this.getMinutes())<10?('0'+m):m;
    ss=(s=this.getSeconds())<10?('0'+s):s;
    return
formatString.replace("#hhh#",hhh).replace("#hh#",hh).replace("#h#",h).replace("#mm#",mm).replace("#m#",m).replace("#ss#",ss).replace("#s#",s).replace("#ampm#",ampm);
         }

getTFID=function(isoDate){ //GET TIME FROM ISO DATE
        if(isoDate.slice(-1)=='-')
                return '';
        isoDate = isoDate.replace(/\D/g, " ");
        var dObj = isoDate.split(" ");
        var newDate = new Date(dObj[0], (dObj[1]-1), dObj[2], dObj[3],
dObj[4], dObj[5]);
        return newDate.customFormat('#h#:#mm##ampm#');

Reply via email to