【发布时间】:2012-10-07 04:46:32
【问题描述】:
如何在 PHP 中将 2012-10-15T13:16:13+00:00 格式的字符串转换为 Unix 时间戳?
【问题讨论】:
标签: php time format timestamp converter
如何在 PHP 中将 2012-10-15T13:16:13+00:00 格式的字符串转换为 Unix 时间戳?
【问题讨论】:
标签: php time format timestamp converter
strtotime() 应该可以处理。
例子
echo strtotime("2012-10-15T13:16:13+00:00") ; // 1350306973
或者
[ghoti@pc ~]$ php -r '$d="2012-10-15T13:16:13+00:00"; print strtotime($d) . "\n";'
1350306973
一旦有了时间戳,就可以用它做任何事情。
[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
【讨论】:
strtotime() 的功能?我找不到...
Baba 提供的解决方案使用DateTime class:
$dt = new DateTime("2012-10-15T13:16:13+00:00");
echo $dt->getTimestamp();
【讨论】: