简体   繁体   中英

Laravel: Get time between two timestamps in diffForHumans format (Carbon)

I am trying to get the time between two dates in diffForHumans format, can anyone help me out to why its throwing this error?

Code:

{{ Carbon\Carbon::createFromTimestamp($clientLogin->exit_timestamp)->diffForHumans($clientLogin->enter_timestamp) }}

Error:

Type error: Argument 1 passed to Illuminate\\Cookie\\Middleware\\EncryptCookies::encrypt() must be an instance of Symfony\\Component\\HttpFoundation\\Response, instance of Illuminate\\View\\View given

建议:将datetime字段定义为日期,这样Laravel就可以将其视为碳实例,因此您可以执行以下操作:

$clientLogin->exit_timestamp->subDays($clientLogin->enter_timestamp)->diffForHumans();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM