0

我正在使用 laravel 7.2。在我的 db 列中,日期和时间存储在一起,就像 2013-08-01 00:00:00 一样。但是在刀片.php 中,我只想像 2013-08-01.here 一样打印日期是我的blade.php 代码

<td>{{$invoice->invoice_created_date}}</td>
<td>IL {{$invoice->invoice_id}}</td>
4

4 回答 4

1

您需要使用date函数来格式化您的日期

喜欢{{ date('Y-m-d', strtotime($invoice->invoice_created_date)) }}

于 2020-06-16T08:21:05.647 回答
0

您可以将 添加invoice_created_datedates模型属性中,它将自动变异为Carbon对象。

Invoice模型中添加日期属性:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Invoice extends Model
{
    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = [
        'invoice_created_date',
    ];
}

在刀片文件中,您可以简单地将日期格式化为您需要的任何格式:

{{ $invoice->invoice_created_date->format('Y-m-d') }}

你可以阅读更多关于 date mutators的内容。

于 2020-06-16T08:40:49.483 回答
0

你可以使用这个功能

public static function dateChange($date)
        {
            $dt = explode(" ", $date);
            return $dt[0];
        }
于 2020-06-16T09:07:05.943 回答
0

你必须像这样使用

{{date('Y-m-d',strtotime($invoice->invoice_created_date))}}
于 2020-06-16T08:24:15.457 回答