简体   繁体   English

如何在PHP中将“ 2012-10-16T14:46:33 + 00:00”转换为Unix Timestamp?

[英]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.

相关问题 如何在PHP中使用类似``2019-07-20T09:20:33 + 00:00''的格式获取Carbon时间 - How to get Carbon time with format like that '2019-07-20T09:20:33+00:00' in PHP PHP获取unix时间戳的00:00:00 - PHP get 00:00:00 of a unix timestamp 如何使用 PHP 将此日期:“16/11/2020 12:00:00 am”转换为“2020-11-16 00:00:00”? - How convert this date: "16/11/2020 12:00:00 a. m." to "2020-11-16 00:00:00" with PHP? 如何以这种格式“ 2013-11-16T12:30:00 + 02:00”在PHP中生成日期时间戳? - How to generate a date timestamp in PHP in this format “2013-11-16T12:30:00+02:00”? 在PHP中优雅地改变2011-10-31T16:22:00到2011-10-31 - Elegantly change 2011-10-31T16:22:00 to 2011-10-31 in php 如何使用PHP将2010-07-28 00:00:00转换为2010年7月28日00:00:00 - How to convert 2010-07-28 00:00:00 to July 28, 2010, 00:00:00 using PHP PHP日期 - 转换自星期三2013年9月10日00:00:00 GMT-0500(EST) - PHP Date - Convert from Wed Sep 10 2013 00:00:00 GMT-0500 (EST) 如何使用laravel(5.8)Carbon将datetimepicker日期(引导程序4)格式16/07/2019 10:00转换为mysql格式2019-07-16 10:00 - how to convert datetimepicker date (bootstrap 4) format 16/07/2019 10:00 to mysql format 2019-07-16 10:00 with laravel (5.8) Carbon 如何在PHP中设置“ 2015-10-06T15:39:07-05:00”这种时间戳? - How do I set “ 2015-10-06T15:39:07-05:00 ” this kind of timestamp in PHP? 我如何从日期时间字符串中减去一个小时,例如:“ 2017-04-20 11:46:00”,并将其转换回PHP中的字符串? - how can i subtract an hour from datetime string eg: “2017-04-20 11:46:00” and convert it back to string in PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM