PDA

View Full Version : gAjax RSS feeds Displayer - date format



mugen
10-22-2009, 09:00 PM
1) Script Title: gAjax RSS feeds Displayer

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex18/gajaxrssdisplayer.htm

3) Describe problem: is it possible to change the date format. for example, i want the date to be displayed as Oct. 22, 2009 1:57PM. I found a date code from Javascript kit Google Ajax feed API (http://www.javascriptkit.com/dhtmltutors/googleajaxfeed2.shtml) . how do i implement this into the script?


var thefeeds=result.feed.entries //get feed contents (JSON array)
for (var i=0; i<thefeeds.length; i++){
var itemdate=new Date(thefeeds[i].publishedDate)
var itemdate_yr=itemdate.getFullYear()
var itemdate_mon=itemdate.getMonth()+1
var itemdate_day=itemdate.getDate()
var output=itemdate_yr + "/" + itemdate_mon + "/" + itemdate_day //format: yyyy/month/day
}

mugen
10-23-2009, 04:23 AM
anybody? i don't really like the full date format. Thursday October 22, 2009. how do you edit the date format in gfeedfetcher.js?

ddadmin
10-23-2009, 08:56 AM
Well, the function:


gfeedfetcher._formatdate=function(datestr, showoptions){
var itemdate=new Date(datestr)
var parseddate=(showoptions.indexOf("datetime")!=-1)? itemdate.toLocaleString() : (showoptions.indexOf("date")!=-1)? itemdate.toLocaleDateString() : (showoptions.indexOf("time")!=-1)? itemdate.toLocaleTimeString() : ""
return "<span class='datefield'>"+parseddate+"</span>"
}

is what formats the date output based on a full date string passed into the function. To get it to output the date in the format October 20, 2009 5:59:00 PM for example, you may try replacing the above with just:


gfeedfetcher._formatdate=function(datestr, showoptions){
var itemdate=new Date(datestr)
var parseddate=itemdate.toLocaleDateString()+" "+itemdate.toLocaleTimeString()
return "<span class='datefield'>"+parseddate+"</span>"
}

mugen
10-23-2009, 03:34 PM
no, that didn't work. is there a way to shorten the format like from the Advanced RSS ticker? thanks. http://dynamicdrive.com/dynamicindex17/rsstickerajax/index.htm

ddadmin
10-24-2009, 08:12 AM
Are you saying the format isn't in the format "October 20, 2009 5:59:00 PM" after the change? To get into the format "Oct 23, 2009 7:05:14 PM", try using the below modified formatdate() function:


gfeedfetcher._formatdate=function(datestr, showoptions){
var mstring=['Jan', 'Feb', 'Mar', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec']
var itemdate=new Date(datestr)
var parseddate=mstring[itemdate.getMonth()] + " " + itemdate.getDate() + " " + itemdate.getFullYear() + " " + itemdate.toLocaleTimeString()
return "<span class='datefield'>"+parseddate+"</span>"
}

mugen
10-24-2009, 07:39 PM
awesome! that's what i was looking for! thanks ddadmin! :D

one more tiny thing. is it possible to force the clock into 12 hour format for all browsers (like the Advanced RSS ticker) IE and Firefox displays it as 12 hour format (which is good). then i tested it out on Chrome, Safari, and Opera, and those three browsers displayed it as a 24 hour format. thanks