Alex Rivera | Logout

Parsing Twitter API Datestamp

Asked 2010-04-09T22:39:49.307
28

I'm using the twitter API to return a list of status updates and the times they were created. It's returning the creation date in the following format:

Fri Apr 09 12:53:54 +0000 2010

What's the simplest way (with PHP or Javascript) to format this like 09-04-2010?

Edit
Report

1 Answer

7

JavaScript can parse that date if you remove the +0000 from the string:

var dStr = "Fri Apr 09 12:53:54 +0000 2010";
dStr = dStr.replace("+0000 ", "") + " UTC";
var d = new Date(dStr);

Chrome -- and I suspect some other non IE browsers -- can actually parse it with the +0000 present in the string, but you may as well remove it for interoperability.

PHP can parse the date with strtotime:

strtotime("Fri Apr 09 12:53:54 +0000 2010");
answered 2010-04-09T22:44:36.887

Your Answer