Carbon\Carbon类的对象无法转换为int

Pat*_*ick 9 php mysql laravel laravel-5.2

我已经找到了这个,我确实找到了一些讨论这个问题的话题,但是我觉得这些都不是我想去的方式,所以我希望能在这里得到更好的消化.

我想从上次更新用户时获取时间戳.

$user->updated_at
Run Code Online (Sandbox Code Playgroud)

如果我运行它,它给了我这个错误

Object of class Carbon\Carbon could not be converted to int
Run Code Online (Sandbox Code Playgroud)

这是因为它在Laravel 5.2中返回一个Carbon实例,我只需要时间戳.

Carbon {#303 ?
  +"date": "2017-01-04 00:35:38.000000"
  +"timezone_type": 3
  +"timezone": "UTC"
}
Run Code Online (Sandbox Code Playgroud)

我如何从碳实例中获取"日期",所以我只得到2017-01-04 00:35:38- 我不知道.000000来自哪里,因为这不会出现在数据库中.在MySQL数据库中,它只显示2016-07-20 20:23:07类型timestamp.

希望得到一些指示和建议

Dek*_*kel 13

Carbon对象有一个toDateTimeString可以使用的方法:

$user->updated_at->toDateTimeString();
Run Code Online (Sandbox Code Playgroud)

它会给你2017-01-04 00:35:38一个字符串的值.