Parsing Twitter Post Dates (JavaScript Dates)
Posted by Steve Onnis at 11:23 AM
2 comments - Categories:
Coldfusion
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 :)
Paul wrote on 10/09/09 12:37 AM
This was my solution I came across this several months ago while building a app that integrates with Twitter: http://pastebin.com/m6cfd7da9 this way I'm not relying on the +0000 when it could be -0000