Php laravel上的格式时间

Php laravel上的格式时间,php,laravel,Php,Laravel,我想知道如何调整我表格上的时间格式? 例如,开始时间=>20:00和结束时间22:00 在我的桌面课程中我有这个 public function up() { Schema::create('course', function (Blueprint $table) { $table->increments('id'); $table->date('date_seance'); $table

我想知道如何调整我表格上的时间格式? 例如,开始时间=>20:00和结束时间22:00

在我的桌面课程中我有这个

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();
        });
    }
class Course extends Model
{
    //
    protected $dates = ['date_seance', 'start_time', 'end_time'];
}
然后,在我的模型课程中我有这个

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();
        });
    }
class Course extends Model
{
    //
    protected $dates = ['date_seance', 'start_time', 'end_time'];
}
在我的视图索引中。刀片

@foreach($course as $item)
<tr>
   <td> {{$item->date_seance->format('d/m/Y') }}</td>
   <td> {{$item->start_time}}</td>
   <td> {{$item->end_time}}</td>
@foreach($课程作为$item)
{{$item->date\u-seance->format('d/m/Y')}
{{$item->start_time}
{{$item->end_time}

谢谢你的帮助

柱的类型是碳类的实例 试试这个怎么样:

 <td> {{$item->date_seance->toDateString() }}</td>
{{$item->date\u seance->toDateString()}
您应该尝试以下方法:

<td> {{date('d/m/Y H:i', strtotime($item->date_seance)) }}</td>
{date('d/m/Y H:i',strotime($item->date_-seance))}

尝试下面的格式,您已经存储在时间中,因此无需在时间中转换

<td> {{date('H:i', $item->start_time) }}</td>
{{date('H:i',$item->start_time)}

我认为你不能在date中使用
'start\u time'
'end\u time'
,因为它们不是

class Course extends Model
{
    protected $dates = ['date_seance'];
}
然后使用

<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>
{{$item->date\u-seance->format('d/m/Y')}
{{date('H:i',strottime($item->start_time))}
{{date('H:i',strottime($item->end_time))}

使用变异子和存取子

  • 用于在数据库中节省时间的Mutator
    setStartTimeAttribute
  • 访问器
    getStartTimeAttribute
    以所需格式显示,即
    h:i或h:i

    public function setStartDateAttribute($value)
    {
        $this->attributes['start_time'] = Carbon::parse($value)->format('H:i');
    }
    public function getStartDateAttribute()
    {
         return Carbon::parse($this->attributes['start_time'])->format('H:i');
    }
    
  • 现在,您可以访问格式化的时间作为
    $object->start\u time
    20:00

    你所说的
    休养是什么意思?您想要一个特定的输出吗?如果是这样,你想要什么输出?@Jerodev:对不起,是的,例如开始时间=>20:00和结束时间22:00,比如
    {{$item->start\u time->format('h:s')}
    @杰罗德夫:我想他是说。。或者更明确地说“如何设置时间格式”,我想user11124425是法语
    Recipher
    Recipper
    的一种翻译,当你说
    我想(找回|找回)一些东西时,它经常被使用。至少,在法语中,这个词是有意义的。@CBACONIER:是的,我是法国人…:-)当我在phpyMyAdmin上录制me字段的une值开始时间(例如20:00)时,我希望在我的表单index.blade.php上获得20:00谢谢,但我的问题不是date mais hour。我想得到实际的小时数。我明白了,你试过$item->start\u time->format('h:I')吗?谢谢,但日期已经确定了。我的问题实际上只有小时数。