我已经搜索过这个,我确实找到了一些讨论这个问题的话题,但是我觉得没有一个是我想要走的路,所以我希望在这里得到更好的建议。
我想从用户上次更新时获取时间戳。
$user->updated_at
如果我运行它,它会给我这个错误
Object of class Carbon\Carbon could not be converted to int
这是因为它在 Laravel 5.2 中返回一个 Carbon 实例,而我只需要时间戳。
Carbon {#303 ▼
+"date": "2017-01-04 00:35:38.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
我如何从碳实例中获取“日期”,所以我只得到
2017-01-04 00:35:38
- 我不知道 .000000 来自哪里,因为它没有出现在数据库中。在 MySQL 数据库中,它只是将 2016-07-20 20:23:07
显示为 timestamp
类型。希望得到一些指点和建议
最佳答案
Carbon
对象有一个 toDateTimeString
方法,您可以使用:
$user->updated_at->toDateTimeString();
它将为您提供值
2017-01-04 00:35:38
作为字符串。关于php - 类 Carbon\Carbon 的对象无法转换为 int,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41454800/