我在操作Carbon日期对象($subscription->updated_at
)时遇到问题:
$thisDate = $subscription->updated_at->date;
$thisDate = Date($graphDateFormat, $thisDate);
Unknown getter 'date'
$thisDate = $subscription->updated_at;
$thisDate = Date($graphDateFormat, $thisDate);
date() expects parameter 2 to be long, object given
var_dump($subscription->updated_at);
结果:
object(Carbon\Carbon)[292]
public 'date' => string '2013-08-21 17:05:19' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
如何在Date()函数中使用Carbon日期?
答案 0 :(得分:2)
您可以使用$subscription->updated_at->timestamp
获取UNIX时间戳,您可以将其传递给date
。使用format()
方法直接在Carbon对象中格式化日期可能更容易:
$thisDate = subscription->updated_at->format($graphDateFormat);