Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript code to display Twitter created_at as xxxx ago

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.

like image 303
Scott Avatar asked Jul 01 '11 14:07

Scott


1 Answers

Using moment.js without any plugin this is the custom format you need to use to parse the awkward Twitter date properly:

var tweetDate = 'Mon Dec 02 23:45:49 +0000 2013';
moment(tweetDate, 'dd MMM DD HH:mm:ss ZZ YYYY', 'en');
like image 77
Oncle Tom Avatar answered Nov 04 '22 06:11

Oncle Tom