我正在使用 Symfony2。从数据库中获取日期时,我需要在我的 index.html.php
中显示日期。
当我打印它时显示如下:DateTime Object ( [date] => 2012-10-09 13:30:23 [timezone_type] => 3 [timezone] => UTC)
但是当我将对象转换为 int 时出现错误:$days2 = floor( $entities->getCreationDate()/(60 * 60 * 24));
Notice: Object of class DateTime could not be converted to int**
最佳答案
如果您想从 DateTime 对象获取整数时间戳,请使用 getTimeStamp method .
$date = new DateTime();
echo $date->getTimestamp();
关于date - 我如何在 symfony2 中将日期对象转换为时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12803127/