如何转换的二氧化碳排放到字符串

问题描述 投票:2回答:2

我有一个这样的集合

0 => array:4 [
  "so" => "SO-1"
  "product_name" => "EXTREME FORTE - BP"
  "created_at" => Carbon @1527481346 {#628
    date: 2018-05-28 04:22:26.0 UTC (+00:00)
  }
  "id" => "5b0b84027475aa1508002623"
]

如何利用唯一的“2018年5月28日”?有人可以帮我解决这个问题?不管怎么说,还是要谢谢你

php laravel collections php-carbon
2个回答
7
投票
$collection_item->created_at->format('Y-m-d');

1
投票

我喜欢这个

$model_item->created_at->toDateString();

因为这坐落在模式protected $dates array所有日期字段是\Carbon\Carbon的类型。

所以上面的代码可以应用到任何日期字段,只要你宣布它作为日期$dates array的模式如下

// this includes created_at and updated_at by default so no need to add it 
protected $dates = ['approved', 'seen_at];
© www.soinside.com 2019 - 2024. All rights reserved.