Laravel- 如何使用 Carbon 检查两个时间戳之间的差异

Laravel- How to check difference between two time stamps using Carbon

我目前在 laravel 5.4 工作,我需要使用 Carbon Class 计算两个可用时间戳之间的差异。但是我收到了这个错误 Call to a member function diffInHours() on string 你们的任何见解都会有所帮助谢谢 :)

用户控制器

class UserController extends Controller
{
 use EncryptDecrypt;
 public function resetPassword($token)
 {
    $decryptTS = trim($this->decryptText($token));
    $split = explode('-', $decryptTS, 2);

    $userId = $split[0];
    $timeStamp = $split[1];
    $timeStamp1=Carbon::createFromTimestampUTC($timeStamp)->toDateTimeString();
    $now = Carbon::now();


    if($timeStamp1->diffInHours($now) <=24)
    {
        echo "valid URL";
    }
    else
    {
        echo "Invalid URL";
    }

  }
}

尝试替换此行:

$timeStamp1=Carbon::createFromTimestampUTC($timeStamp)->toDateTimeString();

与:

$timeStamp1=Carbon::createFromTimestampUTC($timeStamp);

第一个 return 字符串不是碳对象