JavaScript code to display Twitter created_at as xxxx ago

Viewed 20193

I need some JS code that will take the created_at value from a Twitter feed and display it as xxxx ago.

I can find examples of creating the xxxx ago bit but not examples of getting the created_at bit into the correct format for JS.

Does anyone have an all in one function to do what I'm after?

example format Tue Apr 07 22:52:51 +0000 2009

Cannot use new Date(Date.parse("Tue Apr 07 22:52:51 +0000 2009")) as it gives an invalid date error in IE.

8 Answers

May be hella late but I just found out splitting the string by spaces and creating variables accordingly, easily allows you to breakdown the date.

// Ex. Thu Sep 28 03:40:33 +0000 2017

var tweetDate = data.tweet[i].created_at;

tweetDate = tweetDate.split(' ');

var tweetMo = tweetDate[1];
Related