2017-05-01 71 views
0

创造我想要一些日期碳从时间戳

<p>{{ Carbon\Carbon::parse($post->created_at)->diffForHumans() }}</p> 

也能正常工作的日期的格式为2017年5月1日10时52分51秒

不过,我也转换将日期存储为unix时间戳。

我该如何将这些转化为约会呢?

我已经尝试过

{{ Carbon\Carbon::createFromTimestamp($post->created_at)->toDateTimeString() }} 

错误 - 非合式数值遇到

转储是

<pre class="xdebug-var-dump" dir="ltr"> 
<small>int</small> 
<font color="#4e9a06">1493637826</font> 
    </pre> 
+1

http://carbon.nesbot.com/docs - 在你的浏览器搜索窗口输入“timestamp” –

+0

这就是我已经尝试Carbon \ Carbon :: createFromTimestamp($ post-> created_at) - > toDateTimeString()} } – LeBlaireau

+0

没有喜悦吗? –

回答

0

最后,我不得不使用gmdate转换的时间戳。

{{ Carbon\Carbon::parse(gmdate("Y-m-d\TH:i:s", $post->date_posted))->diffForHumans() }} 

这很奇怪,因为它应该按照Robbie Averill的建议。