Javascript does not have its own built-in function for formatting dates. You would have to create one from scratch. I found this function somewhere in the net. I forgot who the owner of this one is but if you (the owner) come across your function, please do let me know. This was very useful and what I needed. Easy to use, no hassles.
Sample usage would be date_format(new Date("07/01/2008"), "!mmmm !d, !yyyy")
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
function date_format(aDate, displayPat){ /******************************************************** * Valid Masks: * !mmmm = Long month (eg. January) * !mmm = Short month (eg. Jan) * !mm = Numeric date (eg. 07) * !m = Numeric date (eg. 7) * !dddd = Long day (eg. Monday) * !ddd = Short day (eg. Mon) * !dd = Numeric day (eg. 07) * !d = Numeric day (eg. 7) * !yyyy = Year (eg. 1999) * !yy = Year (eg. 99) ********************************************************/ intMonth = aDate.getMonth(); intDate = aDate.getDate(); intDay = aDate.getDay(); intYear = aDate.getFullYear(); var months_long = new Array ('January','February','March','April', 'May','June', 'July','August','September','October','November','December') var months_short = new Array('Jan','Feb','Mar','Apr','May','Jun', 'Jul','Aug','Sep', 'Oct','Nov','Dec') var days_long = new Array('Sunday','Monday','Tuesday','Wednesday', 'Thursday','Friday','Saturday') var days_short = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat') var mmmm = months_long[intMonth] var mmm = months_short[intMonth] var mm = intMonth < 9?'0'+ (1 + intMonth) + '':(1+intMonth)+''; var m = 1+intMonth+''; var dddd = days_long[intDay]; var ddd = days_short[intDay]; var dd = intDate<10?'0'+intDate+'':intDate+''; var d = intDate+''; var yyyy = intYear; century = 0; while((intYear-century)>=100) century = century + 100; var yy = intYear - century if(yy<10) yy = '0' + yy + ''; displayDate = new String(displayPat); displayDate = displayDate.replace(/!mmmm/i,mmmm); displayDate = displayDate.replace(/!mmm/i,mmm); displayDate = displayDate.replace(/!mm/i,mm); displayDate = displayDate.replace(/!m/i,m); displayDate = displayDate.replace(/!dddd/i,dddd); displayDate = displayDate.replace(/!ddd/i,ddd); displayDate = displayDate.replace(/!dd/i,dd); displayDate = displayDate.replace(/!d/i,d); displayDate = displayDate.replace(/!yyyy/i,yyyy); displayDate = displayDate.replace(/!yy/i,yy); return displayDate; } |
your site is really helpful…keep it up…although, i’m not that good in computer…i’m learning thru u, guys…My blog is more on a personal journal…or some inspirational stuff…