StealthRT
StealthRT

Reputation: 10542

Php convert datetime from twitter feed

Hey all i have this date for one of my twitter feeds:

Tue Apr 16 17:39:59 +0000 2013

Problem is that this code below does not seem to format it?

$date = new DateTime('Tue Apr 16 17:39:59 +0000 2013');
echo $date->format('Y-m-d H:i:s');

It just shows up as a blank page.

What could i be doing wrong?

Upvotes: 0

Views: 422

Answers (3)

i've tested out your code on a console app with php and works fine. I think that maybe you have a problem with the code that display the page in the browser. Other thing that you can try is to inspect the source of the page and see if is showing there. BTW, i'm using PHP 5.4.7

Upvotes: 0

Navnath Godse
Navnath Godse

Reputation: 2225

Try this

$date = 'Tue Apr 16 17:39:59 +0000 2013';
echo gmdate('Y-m-d H:i:s', strtotime($date));

Upvotes: 0

John Conde
John Conde

Reputation: 219794

Try:

$date = DateTime::createFromFormat('D M j H:i:s O Y', 'Tue Apr 16 17:39:59 +0000 2013');
echo $date->format('Y-m-d H:i:s');

See it in action

Upvotes: 5

Related Questions