dongyan3018 2017-12-27 12:05
浏览 309
已采纳

在laravel字段中显示时间戳的日期部分

I have a table data value in my laravel blade:

<td>{{$events->updated_at}}</td>

which just reads from a database timestamp value. It works and displays as it should but the controller is reading the full timestamp, which we need, but in this table data cell I only want to display the date portion.

So instead of 2017-12-27-00:00:00, I just want to show 2017-12-27.

Is there a special way I should go about this in a laravel blade?

  • 写回答

3条回答 默认 最新

  • dqayok7935 2017-12-27 12:08
    关注

    All the timestamps in an Eloquent object use the Carbon class, making formatting easier. So all you have to do is use the Carbon format functions:

    <td>{{$events->updated_at->toDateString()}}</td>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?