Convert data from email header

蹲街弑〆低调 提交于 2019-12-03 07:19:02

You should be using DateTime for this, specifically DateTime::createFromFormat():

$str = 'Wed, 28 Apr 2010 21:59:49 -0400';
$date = DateTime::createFromFormat( 'D, d M Y H:i:s O', $str);

Now, you have a Date object in $date, and you can grab the unix timestamp (if that's what you want), or you can format it into a date for MySQL.

echo $date->getTimestamp(); // Outputs: 1272506389
echo $date->format( 'Y-m-d H:i:s'); // For MySQL column, 2010-04-28 21:59:49

You can see it working in the demo.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!