仅在Laravel Events中返回时间戳

问题描述 投票:4回答:1

当我听一个事件时,返回的laravel时间戳格式如下:

created_at: {
  date:"2018-03-04 05:24:25.000000",
  timezone:"UTC"
  timezone_type:3
  }

我怎样才能在laravel事件中返回时间戳,或者像这样:

2018-03-04 05:24:25.000000
php laravel laravel-5.6
1个回答
2
投票

这样做:

$dateTime = $object->created_at->toDateTimeString();

或者你使用的模型中的create an accessor

public function getCreatedAtStringAttribute($value)
{
    return $value->toDateTimeString();
}

并使用它:

$dateTime = $object->created_at_string;
© www.soinside.com 2019 - 2024. All rights reserved.