Viewing by month: October 2009

Oct 8 2009

Parsing Twitter Post Dates (JavaScript Dates)

Came into a little problem while accessing the Twitter API status post date values.  Seems i guess the assume most people will be accessing the API using AJAX or something because the dates the return are formatted like a JavaScript date is formatted, which unfortunatly can't be parse with the ColdFusion date parsing functions.

To solve this problem you need to restructure the date string into a format that the DateParse() function can deal with and convert into a date object.  Here is a little UDF you can use to do it.

<cfscript>
 function parseJSDate(dateString) {
  // starting off with "Fri Sept 19 16:30:00 +0000 2009"
  
  // Move the year value to the front
  var date = ListSetAt(dateString, 1, listLast(dateString, " "), " ");
  // now it is "2009 Sept 19 16:30:00 +0000 2009"
  
  date = listFirst(date, "+");
  // now it is "2009 Sept 19 16:30:00"
  
  // now return it parsed as a date value
  return ParseDateTime(date);
  }
</cfscript>

Now of course twitter does not include any timezone information in the date so you will have to add your own timezone info to get the correct date/time for your needs.

Hope people find this of use :)

2 comments - Posted by Steve Onnis at 11:23 AM - Categories: Coldfusion