Results 1 to 6 of 6

Thread: gAjax RSS feeds Displayer - date format

  1. #1
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default gAjax RSS feeds Displayer - date format

    1) Script Title: gAjax RSS feeds Displayer

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...sdisplayer.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 . how do i implement this into the script?

    Code:
    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
    }

  2. #2
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    anybody? i don't really like the full date format. Thursday October 22, 2009. how do you edit the date format in gfeedfetcher.js?

  3. #3
    Join Date
    Aug 2004
    Posts
    10,140
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Well, the function:

    Code:
    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:

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

  4. #4
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    no, that didn't work. is there a way to shorten the format like from the Advanced RSS ticker? thanks. http://dynamicdrive.com/dynamicindex...ajax/index.htm

  5. #5
    Join Date
    Aug 2004
    Posts
    10,140
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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:

    Code:
    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>"
    }
    DD Admin

  6. The Following User Says Thank You to ddadmin For This Useful Post:

    mugen (10-24-2009)

  7. #6
    Join Date
    Oct 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    awesome! that's what i was looking for! thanks ddadmin!

    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
    Last edited by mugen; 10-25-2009 at 05:25 AM. Reason: one more question

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •