dsn5510 2019-02-27 10:26
浏览 67
已采纳

laravel上的格式时间

I would like to know how to recuperate the format time on my form please? For example start_time => 20:00 and end_time 22:00.

In my table course I have this

public function up()
    {
        Schema::create('course', function (Blueprint $table) {
            $table->increments('id');
            $table->date('date_seance');
            $table->time('start_time');
            $table->time('end_time');
            $table->timestamps();
        });
    }

Then, on my model course I have this

class Course extends Model
{
    //
    protected $dates = ['date_seance', 'start_time', 'end_time'];
}

In my view index.blade

@foreach($course as $item)
<tr>
   <td> {{$item->date_seance->format('d/m/Y') }}</td>
   <td> {{$item->start_time}}</td>
   <td> {{$item->end_time}}</td>

Thank you for your help.

  • 写回答

5条回答 默认 最新

  • dongyuan7110 2019-02-27 11:18
    关注

    I don't think you can use 'start_time' and 'end_time' in date since they are not.

    class Course extends Model
    {
        protected $dates = ['date_seance'];
    }
    

    Then use

    <td> {{$item->date_seance->format('d/m/Y') }}</td>
    <td> {{date('H:i', strtotime($item->start_time)) }}</td>
    <td> {{date('H:i', strtotime($item->end_time)) }}</td>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度