I have a Unix timestamp in a table and want to convert it to a human-readable format using Carbon. How can I achieve this?
e.g.
1487663764.99256To
2017-02-24 23:23:14.654621
Did you check the Carbon docs? I think this is what you're looking for:
Carbon::createFromTimestamp(-1)->toDateTimeString(); Check out this article: http://carbon.nesbot.com/docs/#api-instantiation
There are several ways to create Carbon instances described in the Carbon documentation, which is linked at the bottom of the project's README. The relevant section is this:
The final two create functions are for working with unix timestamps. The first will create a Carbon instance equal to the given timestamp and will set the timezone as well or default it to the current timezone. The second, createFromTimestampUTC(), is different in that the timezone will remain UTC (GMT). The second acts the same as Carbon::createFromFormat('@'.$timestamp) but I have just made it a little more explicit. Negative timestamps are also allowed.
So you can just do:
$carbon = Carbon::createFromTimestamp($dbResult['SomeTimestampColumn']);