【问题标题】:Format DATETIME during laravel blade foreach loop to only show time在 laravel Blade foreach 循环期间格式化 DATETIME 以仅显示时间
【发布时间】:2021-02-26 10:41:36
【问题描述】:

这是我的循环。打印多条记录以及日期/时间列

@foreach($tableData as $i)
            <tr>
                <th scope="row">{{$i->name}}</th>
                <td>{{$i->duration}}</td>
                <td>{{$i->friendsAmount}}</td>
                <td>{{$i->time)}}</td>
            </tr>
@endforeach

这会打印在时间列下

2020-11-14 19:42:00

我只希望它显示时间

19:42:00

【问题讨论】:

    标签: php mysql laravel foreach eloquent


    【解决方案1】:

    您可以使用 轻松做到这一点:

    {{ \Carbon\Carbon::parse($i->time)->format('H:i:s') }}
    

    【讨论】:

      【解决方案2】:

      你可以使用php date_format函数:

      {{ date_format($i->time, 'h:i A') }}
      {{ date_format($i->time, 'h:i:s') }}
      

      如果是字符串:

      {{ date_format(date_create($i->time), 'h:i A') }}
      {{ date_format(date_create($i->time), 'h:i:s') }}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-24
        • 2021-08-18
        • 1970-01-01
        • 2017-03-26
        • 2011-08-14
        • 1970-01-01
        • 2019-08-29
        相关资源
        最近更新 更多