【问题标题】:How to use carbon or map function to format created_at?如何使用 carbon 或 map 函数来格式化 created_at?
【发布时间】:2018-10-21 18:47:43
【问题描述】:

我在管理控制面板中创建表 CRUD,我将使用地图功能更改控制器中日期(列 created_at)的格式,并在数据库中的表管理中使用集合或碳, 我需要这样的日期(2017 年 1 月 2 日)

【问题讨论】:

    标签: laravel


    【解决方案1】:

    你可以在 carbon 中使用 toFormattedDateString:

    $user->created_at->toFormattedDateString();  
    

    您也可以从模型更改格式

    在您的模型中添加这样的访问器方法:

    public function getCreatedAtAttribute($date)
    {
        return Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('Ym-d');
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-01
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 2022-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多