php,请求中将字符串日期转换为日期时间

php, conversion of string date to DateTime in request

所以我目前有一个请求发送到函数:

$request->date

在这种情况下,日期是一个字符串“2019-10-15”

该函数期望 \DateTime $scheduled 作为该日期的参数

我怎样才能正确地(使用 Carbon/laravel)将这个日期字符串转换为发送它的请求部分中的日期时间?

在你需要日期的控制器中,使用这个:

$date = Carbon::parse($request->date);

您可以从那个日期

简单地实例化一个DateTime
$scheduled = new \DateTime($request->date);