[英]How to convert “2012-10-16T14:46:33+00:00” into Unix Timestamp in PHP?
如何将格式为2012-10-15T13:16:13+00:00
的字符串转换为PHP中的Unix时间戳?
strtotime() should be able to handle it. strtotime()应该能够处理它。
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) . "\n";'
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)."\n";'
Mon Oct 15 09:16:13 EDT 2012
Solution provided by Baba that uses the DateTime class : Baba提供的使用DateTime类的解决方案:
$dt = new DateTime("2012-10-15T13:16:13+00:00");
echo $dt->getTimestamp();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.