Return 时间戳仅在 Laravel 个事件中
Return the timestamps only in Laravel Events
当我收听一个事件时,laravel 的 returned 时间戳格式如下:
created_at: {
date:"2018-03-04 05:24:25.000000",
timezone:"UTC"
timezone_type:3
}
如何才能 return 仅在 laravel 事件或类似这样的事件中使用时间戳:
2018-03-04 05:24:25.000000
只需这样做:
$dateTime = $object->created_at->toDateTimeString();
或create an accessor在您使用的模型中:
public function getCreatedAtStringAttribute($value)
{
return $value->toDateTimeString();
}
并使用它:
$dateTime = $object->created_at_string;
当我收听一个事件时,laravel 的 returned 时间戳格式如下:
created_at: {
date:"2018-03-04 05:24:25.000000",
timezone:"UTC"
timezone_type:3
}
如何才能 return 仅在 laravel 事件或类似这样的事件中使用时间戳:
2018-03-04 05:24:25.000000
只需这样做:
$dateTime = $object->created_at->toDateTimeString();
或create an accessor在您使用的模型中:
public function getCreatedAtStringAttribute($value)
{
return $value->toDateTimeString();
}
并使用它:
$dateTime = $object->created_at_string;