如何将“2012-10-16T14:46:33 + 00:00”转换为PHP中的Unix时间戳?
问题描述:
How do you convert a string in the format 2012-10-15T13:16:13+00:00
into a Unix Timestamp in PHP?
如何转换格式为 2012-10-15T13:16:13 + 00的字符串: 00 code>到PHP中的Unix时间戳? p>
div>
答
strtotime() should be able to handle it.
Example
echo strtotime("2012-10-15T13:16:13+00:00") ; // 1350306973
Or
[ghoti@pc ~]$ php -r '$d="2012-10-15T13:16:13+00:00"; print strtotime($d) . "
";'
1350306973
Once you have a timestamp, you can do anything with it.
[ghoti@pc ~]$ php -r '$d="2012-10-15T13:16:13+00:00"; $t=strtotime($d); print strftime("%+", $t)."
";'
Mon Oct 15 09:16:13 EDT 2012
答
Solution provided by Baba that uses the DateTime class:
$dt = new DateTime("2012-10-15T13:16:13+00:00");
echo $dt->getTimestamp();