1

I've been trying to convert Twilio's convoluted time format (Wed, 21 Oct 2015 19:19:53 +0000) into timestamp so I can format it into something more digestible in PHP. I've tried various methods but none works.

Can somebody please shed some light?

Roy
  • 269
  • 2
  • 6
  • 12

1 Answers1

5

Just use DateTime::createFromFormat($format, $timestring), then call getTimestamp() on the object it returns:

$datetime = DateTime::createFromFormat("D, j M Y G:i:s O", "Wed, 21 Oct 2015 19:19:53 +0000");
//or $datetime = DateTime::createFromFormat("(D, j M Y G:i:s O)", "(Wed, 21 Oct 2015 19:19:53 +0000)");
$timestamp = $datetime->getTimestamp();

And actually, it looks like it is DateTime::RFC1123 format, so you can just do:

$datetime = DateTime::createFromFormat(DateTime::RFC1123, "Wed, 21 Oct 2015 19:19:53 +0000");
dave
  • 62,300
  • 5
  • 72
  • 93