Is there a function to convert the created_at Twitter API to the correct format for ColdFusion 8+?

The Twitter API discards dates (created_at) from api.twitter.com in JSON format in the following format:

"Friday December 10 17:12:00 +0000 2010" (<- notice that the year is at the end)

ColdFusion 9 is not like this format and gives an error.

I tried various built-in ColdFusion date functions, but to no avail. And I did not find anything useful on cflib.org. So, does anyone have a function for this?

+4
source share
3 answers

You can easily treat this line as a space-delimited list and make a friendlier line. Since arrays are faster than lists, I get them into the array as quickly as possible, and then work with it.

public string function getSaneTwitterDate(strDateIn) output="false"{ var arrOrigDate = listToArray(strDateIn, ' '); var strNewDate = arrOrigDate[2] & ' ' & arrOrigDate[3] & ' ' & arrOrigDate[6]; return dateFormat(strNewDate, 'yyyy-mm-dd'); } 

This does not take into account the time offset or includes time information, but it would be easy to add.

+2
source

try http://pastebin.com/GuXu8Dy1

 <cfscript> function twitterDate(date,offset) { var retDate = listtoarray(date, " "); var thisDay = retDate[1]; var thisMonth = retDate[2]; var thisDate = retDate[3]; var thisTime = timeformat(retDate[4], "h:mm tt"); var thisYear = retDate[6]; var thisReturn = ""; var thisFormat = "#thisMonth#, #thisDate# #thisYear#"; thisFormat = dateformat(thisFormat, "m/d/yy") & " " & thisTime; thisFormat = dateadd("s", offset, thisFormat); thisFormat = dateadd("h", 1, thisFormat); longFormat = dateformat(thisFormat, "yyyy-mm-dd") & " " & timeformat(thisFormat, "HH:mm:ss"); thisReturn = longFormat; return thisReturn; } </cfscript> 
+2
source
 <cffunction name="parseTwitterDateFormat" output="false" returntype="String" hint="I return a date in a useable date format."> <cfargument name="twitterDate" required="true" type="string" hint="The Twitter date." /> <cfset var formatter = CreateObject("java", "java.text.SimpleDateFormat").init("EEE MMM d kk:mm:ss Z yyyy") /> <cfset formatter.setLenient(true) /> <cfreturn formatter.parse(arguments.twitterDate) /> </cffunction> 

Credit goes to Matt Gifford's monkeyTweet library https://github.com/coldfumonkeh/monkehTweets

+2
source

All Articles