Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to change Twitter-API datetime's to a timestamp

The Twitter API sends created_at datetimes like this:

"created_at": "Mon Jul 25 05:51:34 +0000 2011", 

What's the best way to convert them in a timestamp and my local timezone (Europe/Zurich)? With strtotime(), I get results like 2013-11-08 20:07:00

Thank you very much

Best regards

like image 495
Ueli Avatar asked Jul 25 '11 23:07

Ueli


1 Answers

$datetime = new DateTime("Mon Jul 25 05:51:34 +0000 2011");
$datetime->setTimezone(new DateTimeZone('Europe/Zurich'));
echo $datetime->format('U');

See DateTime, DateTime::format(), DateTime::setTimezone(), DateTimeZone and date()

like image 127
KingCrunch Avatar answered Nov 16 '22 01:11

KingCrunch